python socketio-打开服务器未返回的数据包



我正在尝试连接到套接字服务器(node.js(,比如http://localhost:4300.在服务器端,它已成功连接,

在我的服务器的日志上

客户端已连接{client_id}

但在我的客户端(python socketio客户端(,它返回异常

服务器未返回打开数据包

有人能帮我解释一下为什么会出现这种异常吗?我一直在按医生说的做。

这可能表明服务器和客户端版本不兼容。对我有效的是固定python engineio和python socketio的包版本:

pip install python-engineio==3.14.2 python-socketio==4.6.0

(来源:https://github.com/miguelgrinberg/python-socketio/issues/586(

关于版本兼容性,另请参阅https://python-socketio.readthedocs.io/en/latest/intro.html

客户端安装的python-engineio-4.0.1 python-socketio-5.1.0我在客户端的代码是

import socketio
sio = socketio.Client(logger=True, engineio_logger=True)

@sio.event
def connect():
print('connection established')

@sio.event
def my_message(data):
print('message received with ', data)
sio.emit('my response', {'response': 'my response'})

@sio.event
def disconnect():
print('disconnected from server')

sio.connect(url='https://socket-io.insertmendoza.com.ar')
sio.wait()

我在服务器中的代码是

import fs from 'fs'
import express from 'express'
import https from 'https'
import socket from 'socket.io'
import moment from 'moment'
import cors from 'cors'
import axios from 'axios'
const app = express()
app.use(cors())
const server = https.createServer({
key: fs.readFileSync('/home/insert/Production/cdn/letsencrypt/live/npm-1/privkey.pem'),
cert: fs.readFileSync('/home/insert/Production/cdn/letsencrypt/live/npm-1/fullchain.pem'),
}, app)
const users = {};
const io = socket(server)
server.listen(443, () => {
console.log('listening on *:443', moment().format('DD/MM/YYYY HH:mm:ss'))
})
"dependencies": {
"axios": "^0.21.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"moment": "^2.29.1",
"nodemon": "^2.0.7",
"socket.io": "3.1.2"
},

终端调试

Attempting polling connection to https://socket-io.insertmendoza.com.ar/socket.io/?transport=polling&EIO=4
Polling connection accepted with {'sid': 'SZHctF0Fa0SMfEiiAAAA', 'upgrades': ['websocket'], 'pingInterval': 25000, 'pingTimeout': 5000}
Engine.IO connection established
Sending packet MESSAGE data 0
Attempting WebSocket upgrade to wss://socket-io.insertmendoza.com.ar/socket.io/?transport=websocket&EIO=4
WebSocket upgrade was successful
Received packet MESSAGE data 0{"sid":"8qEnsIwaom7Tgl8ZAAAB"}
Namespace / is connected
connection established
Received packet MESSAGE data 2["yourID","8qEnsIwaom7Tgl8ZAAAB"]
Received event "yourID" [/]
Received packet MESSAGE data 2["allUsers",{"8qEnsIwaom7Tgl8ZAAAB":"8qEnsIwaom7Tgl8ZAAAB"}]
Received event "allUsers" [/]
Received packet PING data 
Sending packet PONG data 
Received packet PING data 
Sending packet PONG data 
Received packet PING data 
Sending packet PONG data 

服务器中是

listening on *:443 26/03/2021 17:56:00
connection Id: 8qEnsIwaom7Tgl8ZAAAB Auth: undefined IP: ::ffff:192.168.88.252 26/03/2021 18:02:20

最新更新