Socket.IO heartbeat not sent

1k Views Asked by At

I've been running a Socket.IO server (https://github.com/mrniko/netty-socketio) , communicating with a client (https://github.com/nkzawa/socket.io-client.java) that runs on an Android emulator. The emulator is hosted on the machine that runs the server. I was able to create the initial connection from the client to the server, and successfully send a message (client to server), but shortly after that the heartbeat failed and the connection was broken:

DEBUG [07:17:45.470] c.c.socketio.transport.NamespaceClient: Client 157e4f73-e26d-459c-ac1c-506628b66a09 for namespace has been disconnected DEBUG [07:17:45.470] c.c.socketio.SocketIOChannelInitializer: Client with sessionId: 157e4f73-e26d-459c-ac1c-506628b66a09 disconnected DEBUG [07:17:45.470] c.c.socketio.transport.NamespaceClient: Client 157e4f73-e26d-459c-ac1c-506628b66a09 for namespace /android/ has been disconnected DEBUG [07:17:45.471]
c.c.socketio.handler.ClientHead: 157e4f73-e26d-459c-ac1c-506628b66a09 removed due to ping timeout DEBUG [07:17:46.119]
c.c.s.transport.WebSocketTransport: Client with was already disconnected. Channel closed!

Server code:

Configuration serverConfig = new Configuration();
serverConfig.setHostname(MACHINE_IP);
serverConfig.setPort(8082);
serverConfig.setPingTimeout(20);
SocketIOServer server = new SocketIOServer(serverConfig);
server.addNamespace("/android/")
server.start()

Client code:

IO.Options options = new IO.Options();
options.transports = new String[]{"websocket"};
options.reconnectionAttempts = 5;
options.reconnectionDelay = 10000;
Socket socket = IO.socket(MACHINE_IP + ":8082/android/", options)

What am I doing wrong? Thanks.

1

There are 1 best solutions below

0
On

I was finally able to resolve the problem myself (there may be other solutions as well).

What I did was:

  1. Start the server on localhost - as it isn't necessary for it to be visible outside of the machine
  2. Connect the client to 10.0.2.2 - which is the way for the emulator to access its host localhost