Skip to content

Cannot connect to socket io server

I have bot socket IO client and server running. I want to have client communicate with server.

Server initialization

this.http_server = net.createServer();
// this didn't work too. Exxentially socket io does not work at all
// = io.listen(typeof port == "number" ? port : process.env.PORT);
console.log("[ManagementServer] Attaching socket IO to HTTP server."); = io(this.http_server);
/// The port does open
this.http_server.listen(typeof port == "number" ? port : process.env.PORT,
    () => {
        console.log('[ManagementServer] IO HTTP server listening on port', this.http_server.address().port)
/// The connection listener is triggered, but IO doesn't bother 
/// replying or something
this.http_server.on("connection", (req, res) => {
    console.log("[ManagementServer] Connection received, but IO ignores it.")
// Never happens"connection", (socket) => {

Client initialization

const srvurl = "http://" + this.remoteAddr + ":" + this.remotePort;

console.log("[UDP_socketio] Connecting to server: ", srvurl)
this.client = socketioclient(srvurl);

this.client.once("connect", () => {
    console.log("[UDP_socketio] Connected to remote server, identificating.")

this.client.on("error", () => {
    console.error("[UDP_socketio] Socket IO connection error.")

Socket IO debug output

I enabled debug, but socket IO debug output is not very useful anyway:

[ManagementServer] Attaching socket IO to HTTP server. initializing namespace / +0ms encoding packet {"type":0,"nsp":"/"} +0ms encoded {"type":0,"nsp":"/"} as 0 +1ms creating instance with opts {"serveClient":false,"path":"/","initialPacket":["0"]} +3ms
[ManagementServer] IO HTTP server listening on port 80
[UDP_socketio] Connecting to server: parse +0ms new io instance for +0ms readyState closed +0ms opening +1ms creating transport "polling" +0ms polling +0ms xhr poll +0ms xhr open GET: +1ms xhr data null +0ms setting transport polling +10ms connect attempt will timeout after 20000 +12ms readyState opening +1ms
[ManagementServer] Connection received, but IO ignores it. connect attempt timed out after 20000 +20s socket close with reason: "forced close" +20s transport not open - deferring close +20s socket closing - telling transport to close +0ms connect_error +2ms cleanup +0ms will wait 1178ms before reconnect attempt +1ms attempting reconnect +1s readyState closed +0ms opening +1ms

Notice that the listener for connection that I added triggers, but socket IO does nothing.

What did not help so far:

  • Removing the connection listener from the this.http_server
  • Changing port used for testing
  • Increasing delay after which client tries to connect
  • Reading documentation. It’s confusing, incomplete, inaccurate and inconsistent.

What could make socket IO ignore all connections like this? Maybe the server is listening for request from different paths? If that’s the case, how to check what path is IO listening on?


Answer works with http/s servers like express (layer 7).

net is a TCP server (layer 4).

So they are not compatible.

3 People found this is helpful