Python socketIO-client连接然后断开连接

时间:2017-10-17 09:41:14

标签: python node.js socket.io python-sockets

我正在尝试将我的python脚本连接到我的nodejs套接字服务器。我的代码看起来像这样 -

节点js(相关部分) -

//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脚本(相关部分) -

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

我在我的控制台中 连接 但在此之后,我收到错误(在python端) -

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

我用谷歌搜索并搜索相关内容,但直到现在都没有。

感谢任何解决方案。

1 个答案:

答案 0 :(得分:0)

我在这里找到了解决此问题的方法:table value constructor data types

尝试将nodejs的socket.io版本从2.0.3更改为1.7.2