使用socket.io,我试图从python客户端连接到node.js服务器,但是我无法使其正常工作。
我有一个简单的node.js socket.io服务器:
const app = require('express')();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
io.on('connection', () => {
console.log("child connected");
});
server.listen(8810, function () {
console.log('listening on *:8810');
});
现在,我想使用python脚本与其连接:
import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
logging.basicConfig()
from socketIO_client import SocketIO, BaseNamespace
socket_io_server = 'http://www.****.nl/'
socket_io_port = 8810
SocketIO(socket_io_server, socket_io_port)
并收到此错误:
WARNING:socketIO-client:www.****.nl:8810//socket.io [engine.io waiting for connection] unexpected status code (404 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET //socket.io/</pre>
</body>
</html>
)
Traceback (most recent call last):
File "C:\WERKMAP\QR controller\client\qrcontroller_client2.py", line 15, in <module>
SocketIO(socket_io_server, socket_io_port)
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 353, in __init__
resource, hurry_interval_in_seconds, **kw)
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 54, in __init__
self._transport
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 62, in _transport
self._engineIO_session = self._get_engineIO_session()
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 83, in _get_engineIO_session
warning_screen.throw(warning)
File "C:\Python27\lib\site-packages\socketIO_client\logs.py", line 35, in _yield_warning_screen
time.sleep(1)
要使它正常工作,我该怎么做?