1

任何调试技巧都会有所帮助,这只是基本实现。

我正在使用此处的确切教程来设置 ngx 套接字客户端: https ://www.npmjs.com/package/ngx-socket-io

服务器的flask-socketio https://flask-socketio.readthedocs.io/en/latest/

服务器端没有显示错误,但发出/接收的注册处理程序方法似乎是盲目的。

服务器日志:

127.0.0.1 - - [28/Jan/2021 10:58:51] "GET /socket.io/?EIO=3&transport=polling&t=NT8Dtbg HTTP/1.1" 200 418 0.000640
(12285) accepted ('127.0.0.1', 37400)
fa1a1d40bbc349c384a121302ef567c7: Received request to upgrade to websocket
127.0.0.1 - - [28/Jan/2021 10:58:51] "GET /socket.io/?EIO=3&transport=polling&t=NT8Dtcd&sid=fa1a1d40bbc349c384a121302ef567c7 HTTP/1.1" 200 235 0.000408
127.0.0.1 - - [28/Jan/2021 10:58:51] "GET /socket.io/?EIO=3&transport=polling&t=NT8DtdE&sid=fa1a1d40bbc349c384a121302ef567c7 HTTP/1.1" 200 235 0.000268
fa1a1d40bbc349c384a121302ef567c7: Upgrade to websocket successful
5002732d42184ba6b453e7d4f35e864e: Received packet PING data None
5002732d42184ba6b453e7d4f35e864e: Sending packet PONG data None

客户端日志:

config: {url: "http://127.0.0.1:5000/", options: {…}}
emptyConfig: {url: "", options: {…}}
eventObservables$: {}
ioSocket: Socket
acks: {}
connected: false
disconnected: true
flags: {}
ids: 0
io: Manager
autoConnect: true
backoff: Backoff {ms: 1000, max: 5000, factor: 2, jitter: 0.5, attempts: 0}
connecting: [Socket]
decoder: Decoder {reconstructor: null, _callbacks: {…}}
encoder: Encoder {}
encoding: false
engine: Socket {secure: false, agent: false, hostname: "127.0.0.1", port: "5000", query: {…}, …}
lastPing: Thu Jan 28 2021 11:00:56

服务器代码(无打印)

@socketio.on('connect')
def test_connect():
    print('\n\nClient connected')

为什么我无法使连接正常工作?谢谢

4

1 回答 1

0

仔细检查当前版本的 socketio 和 engineio 的 npm/python 环境。 https://github.com/miguelgrinberg/python-socketio

d7e95928d73c42fab431e94ce2df40fc: Sending packet OPEN data {'sid': 'd7e95928d73c42fab431e94ce2df40fc', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}


Client connected
d7e95928d73c42fab431e94ce2df40fc: Sending packet MESSAGE data 0
于 2021-01-28T19:46:40.837 回答