0

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

  • 1
    Most likely [this](https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie). – greeble31 Feb 12 '20 at 20:25
  • Presumably your android application is running on a phone. Is that phone on your local WiFi network? If not, then it won't be able to connect over the mobile network to your local server because of your local network's router firewall. – jfriend00 Feb 13 '20 at 01:02
  • @greeble31 It was exactly that, thanks, you made my day. jfriend00 Thanks to you too for the quick reply – Lorenzo Fioroni Feb 13 '20 at 08:25

0 Answers0