1

I'm having a lot of difficulty with a very simple task. I'm attempting to set up a socket.io client in node js, which should then communicate with a local socket.io server setup in python (using the python bindings here. The issue I'm having is the server is detecting the client, but the client never seems to receive the 'connect' event. I suspect this is an issue with the way I've deployed the server asynchronously, but I'm really not sure. The code for each file is below:

server.py

import socketio
from aiohttp import web

HOST = '127.0.0.1'
PORT = 10001

# create a Socket.IO server
sio = socketio.AsyncServer(async_mode='aiohttp', logger=True, engineio_logger=True)

app = web.Application()
sio.attach(app)

@sio.on('connect')
def connect(sid, environ):
    print('connect ', sid)

if __name__ == '__main__':
    web.run_app(app, host=HOST, port=PORT)

client.js

const io = require('socket.io-client');

const HOST = '127.0.0.1';
const PORT = '10001';

const socket = io(`http://${HOST}:${PORT}`);
console.log('Socket instantiated!');

socket.on('connect', () => {
    console.log(`socket connected: ${socket.connected}`);
});

The output I would expect is to see the server print out that the client has connected, and then for the client to print out that it has connected too. However, the client never seems to receive the 'connect' event, so never prints anything to the console.

Finally, an example of the server's output is:

Server initialized for aiohttp.
======== Running on http://127.0.0.1:10001 ========
(Press CTRL+C to quit)
1c17586e4c7e49b48abefea2fba460e6: Sending packet OPEN data {'sid': '1c17586e4c7e49b48abefea2fba460e6', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
connect  1c17586e4c7e49b48abefea2fba460e6
1c17586e4c7e49b48abefea2fba460e6: Sending packet MESSAGE data 0

While the client's output is annoyingly just

$ node mySocket.js
Socket instantiated!

and then it just hangs doing nothing.

I'm clearly misunderstanding something here, so thank you in advance!

Small update

I quickly tested using the python socketio client, and succesfully got an actual connection, so this should narrow it down to something I've done in the JS client.

1 Answer 1

2

Well, I ended up downgrading from socket.io-client 3.00 (did not see there was this major release 3 days ago) back to 2.3.1, and everything started working again! However, based on the lack of issues listed on Github, I'm guessing this is not a bug that is affecting everyone.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I spent a lot of time debugging this issue. Then I downgraded to 2.3.1 which fixed it for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.