简体   繁体   中英

Python socketIO-client connects and then disconnects

I am trying to connect my python script to my nodejs socket server. My code looks like this-

node js (relevant part)-

//using socket.io@2.0.3
//PORT 8008
io.on('connection', function(socket){
    console.log('connected');
    socket.on('disconnect', function(){

    });
    socket.on('message', function incoming(message){
        console.log(message);
        var data=JSON.parse(message);
        console.log(data);
        socket.broadcast.emit('message', message);
    });
});

python script (relevant part)-

# using socketIO_client --0.7.2
socketIO = SocketIO('localhost', 8008)
socketIO.wait()

I am getting connecting in my console but after that, I am getting error (on python side) -

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/socketIO_client/__init__.py", line 353, in __init__
    resource, hurry_interval_in_seconds, **kw)
  File "/usr/local/lib/python2.7/dist-packages/socketIO_client/__init__.py", line 54, in __init__
    self._transport
  File "/usr/local/lib/python2.7/dist-packages/socketIO_client/__init__.py", line 62, in _transport
    self._engineIO_session = self._get_engineIO_session()
  File "/usr/local/lib/python2.7/dist-packages/socketIO_client/__init__.py", line 76, in _get_engineIO_session
    transport.recv_packet())
StopIteration

I googled and searched for related stuff but nothing till now.

Any approach to solution is appreciated.

I found a solution for this problem here: https://github.com/invisibleroads/socketIO-client/issues/159

Try to change the socket.io version of nodejs from 2.0.3 to 1.7.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM