使用python和Typscript连接两个套接字(客户端和服务器)



问题

我在连接两个插座时遇到问题。这种关系是客户端和服务器(单一连接)。

我有什么

我能够使用python3成功地运行我的服务器,也能够成功地托管连接套接字的Angular应用程序,但当我试图发出事件或从我的Angular代码进行连接时,我在握手过程中遇到了400错误,python服务器端的错误看起来像这个

客户端正在使用不受支持的Socket.IO或Engine.IO协议版本(此错误的进一步发生将以INFO级别记录)

我想要做的连接到服务器,让它发送json负载和稍后的视频馈送。

Python3代码

import eventlet
import socketio
sio = socketio.Server(cors_allowed_origins='*')
app = socketio.WSGIApp(sio, static_files={
'/': {'content_type': 'text/html', 'filename': 'index.html'}
})

@sio.on('sensorframe')
def message(sid, data):
print('message ', data)
@sio.event
def controller(command: str):
print(command)
if __name__ == '__main__':
eventlet.wsgi.server(eventlet.listen(('127.0.0.1', 8010)), app)

python-socketio版本=5.0.4

import * as io from 'socket.io-client';
export class GuagesComponent implements OnInit {
private sensorframe: object;
public socket: SocketIOClient.Socket;
constructor(
private ref: ChangeDetectorRef,
private _socketService: SocketsService
) {
this.socket = io.connect('http://127.0.0.1:8010', {
reconnection: true,
reconnectionDelay: 5000,
reconnectionDelayMax: 5000,
reconnectionAttempts:  5,
transports: ['websocket', 'polling', 'flashsocket', 'xhr-polling'],
});
console.log(io.protocol); // 4
}
private eventFire(): void {
this.socket.emit('controller', 'data from client');
}
public ngOnInit(): void {
}
}

日志输出

python3 server.py 
(149348) wsgi starting up on http://127.0.0.1:8010
(149348) accepted ('127.0.0.1', 51348)
The client is using an unsupported version of the Socket.IO or Engine.IO protocols (further occurrences of this error will be logged with level INFO)
127.0.0.1 - - [15/Jan/2021 17:58:38] "GET /socket.io/?EIO=3&transport=websocket HTTP/1.1" 400 195 0.000308
(149348) accepted ('127.0.0.1', 51392)

进入版本。Socket IO客户端在前端很好,但我不得不将此版本用于python3

engineio==3.13.2和python socketio==4.6.0

最新更新