Code Monkey home page Code Monkey logo

Comments (10)

naderio avatar naderio commented on August 21, 2024

This plugin works well on HTTPS, at least with standard port 443

please add error event handler as following and see the outcome

const SocketIO = require('nativescript-socket.io');
let socket = SocketIO.connect(ENDPOINT);
socket.on('error', (error) => {
  console.dump(error);
});

from nativescript-socket.io.

wiliarko avatar wiliarko commented on August 21, 2024

on my server i create certificate :

openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem

and node server :

var fs = require('fs');
var options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

var app = require('https').createServer(options,handler)
var io = require('socket.io')(app);

app.listen(8000);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

i cannot conect

var SocketIO = require('nativescript-socket.io');
   SocketIO.enableDebug(); // optionnal

   var socket = SocketIO.connect('https://192.168.1.185:8000', []);

   socket.on('connect', function(){
     console.log('connect berhasil');
   });
   socket.on('error', (error) => {
       console.log('error');
     console.dump(error);
   });

and no error

from nativescript-socket.io.

naderio avatar naderio commented on August 21, 2024

please do curl -v https://192.168.1.185:8000/socket.io/
if that outcomes {"code":0,"message":"Transport unknown"} then you should be able to connect, otherwise I have no idea what is happening here

from nativescript-socket.io.

wiliarko avatar wiliarko commented on August 21, 2024

this is result from my web production

Kreasindos-MacBook-Pro:~ kct$ curl -v https://demo.worksaurus.com:58082/socket.io/
*   Trying 128.199.84.205...
* Connected to demo.worksaurus.com (128.199.84.205) port 58082 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.worksaurus.com
* Server certificate: COMODO RSA Domain Validation Secure Server CA
* Server certificate: COMODO RSA Certification Authority
* Server certificate: AddTrust External CA Root
> GET /socket.io/ HTTP/1.1
> Host: demo.worksaurus.com:58082
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Date: Thu, 30 Mar 2017 15:54:07 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
* Connection #0 to host demo.worksaurus.com left intact
{"code":0,"message":"Transport unknown"}

and i still cannot connet to the socket

from nativescript-socket.io.

wiliarko avatar wiliarko commented on August 21, 2024

it'is my javascript code


var createViewModel = require("./main-view-model").createViewModel;

function onNavigatingTo(args) {
    var page = args.object;
    page.bindingContext = createViewModel();

    var SocketIO = require('nativescript-socket.io');
    SocketIO.enableDebug(); // optionnal
    
    var socket = SocketIO.connect('https://demo.worksaurus.com:58082', []);

    socket.on('connect', function(){
      console.log('connect berhasil');
    }); 
    socket.on('error', (error) => {
        console.log('error');
      console.dump(error);
    });

    for(var i in socket.android){
        console.log(i);
    }

    console.log("hasil : "+socket.android.connected());

}

exports.onNavigatingTo = onNavigatingTo;

from nativescript-socket.io.

wiliarko avatar wiliarko commented on August 21, 2024

Could you try directly to my socket production ?

from nativescript-socket.io.

naderio avatar naderio commented on August 21, 2024

please test with standard port for HTTPS (443), with android and ios
this could be a port issue

from nativescript-socket.io.

naderio avatar naderio commented on August 21, 2024

@wiliarko is this issue persisting?

from nativescript-socket.io.

zoeitsolutions avatar zoeitsolutions commented on August 21, 2024

@wiliarko if you are using this with android, it won't connect, since android doesn't support non-standard ports over https, hence 443. You will either need to proxy it or run it over 443 as suggested.

from nativescript-socket.io.

naderio avatar naderio commented on August 21, 2024

thank you @zoeitsolutions for the clarification.
@wiliarko I presume this sorts the matter out .. closing

from nativescript-socket.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.