Java client not connecting to NodeJS Socket.IO server

654 views Asked by At

I'm trying to implement a simple socket.io client in my android application to connect to a server hosted on my computer. With some examples I've managed to connect with the android app to https://socket-io-chat.now.sh/, so I think the code should be right. The problem is that if I clone the chat example's repo and I run it on my computer, it works like a charm from each browser connected in my network but it does not from my app, which continues to fire EVENT_CONNECT_ERROR.

As I've said since I can successfully connect to the online server, I don't think the problem could be in the client code, but since also the server code is the same, I can't image anything else.

The only thing I've noticed is that the online server uses secure connection while I try to connect to my local machine using http://192.168.178.25:3000... Don't know if it means anything.

This is my client code:

    var socket = IO.socket("http://192.168.178.25:3000")  //https://socket-io-chat.now.sh/ http://192.168.178.25:3000
    socket.on(Socket.EVENT_CONNECT_ERROR, Emitter.Listener {
        Log.e("fluid", "Error connecting :( ")
    }).on(Socket.EVENT_CONNECT, {
        Log.i("fluid", "Connected :) ")
    })
    socket.connect()

The server code is the one of this repo, I've only changed server.listen(port, () => { to server.listen(port, "0.0.0.0", () => {

Thanks in advance for any help,

Lorenzo

0

There are 0 answers