我正在尝试连接到flask-socketio服务器,在const socket = io.connect(host);
上,我可以在服务器日志上打印,但是并没有将试图发送给客户端的功能发回来。
客户端代码:
componentDidMount() {
const socket = io.connect(host);
console.log('testing', socket.connected);
socket.on('connected', function(data) {
console.log('listening connected...');
});
console.log('testing', socket.connected);
}
服务器端代码:
@socketio.on("connect")
def connectServer():
print("Client connected")
socketio.emit("connected")
服务器端日志:
Client connected
192.168.56.1 - - [12/Dec/2019 18:25:53] "GET /socket.io/?EIO=3&transport=polling&t=Mxwxb9l HTTP/1.1" 200 373 0.003000
192.168.56.1 - - [12/Dec/2019 18:25:53] "POST /socket.io/?EIO=3&transport=polling&t=MxwxbAA HTTP/1.1" 400 186 0.000000
Client connected
192.168.56.1 - - [12/Dec/2019 18:25:56] "GET /socket.io/?EIO=3&transport=polling&t=Mxwxc2Y HTTP/1.1" 200 373 0.001000
192.168.56.1 - - [12/Dec/2019 18:25:56] "POST /socket.io/?EIO=3&transport=polling&t=Mxwxc31 HTTP/1.1" 400 186 0.001000
Client connected
192.168.56.1 - - [12/Dec/2019 18:26:00] "GET /socket.io/?EIO=3&transport=polling&t=Mxwxcxb HTTP/1.1" 200 373 0.002000
192.168.56.1 - - [12/Dec/2019 18:26:00] "POST /socket.io/?EIO=3&transport=polling&t=Mxwxcy6 HTTP/1.1" 400 186 0.000000
和客户端控制台日志:
testing false
C:\OwnProjects\safetync\src\Screens\Authentication\signup.js:47 testing false
更新: 这是我从engineio.logger = TRUE获得的:-
Client connected
5ec1a26df0c245238439879c025ce05a: Client is gone, closing socket
5ec1a26df0c245238439879c025ce05a: Client is gone, closing socket
50a596f672014296b90befb5cf69d139: Sending packet MESSAGE data 2["connected","testign"]
a9b0114871554baea9cc33ea3637eccd: Sending packet MESSAGE data 2["connected","testign"]
0ddad6a7f8f6475ead11a8029ec04e0c: Sending packet MESSAGE data 2["connected","testign"]
6b42db33dded40e691ac074d2b0e08f3: Sending packet MESSAGE data 2["connected","testign"]
ccf27e3a769949f7bda025baf6101650: Sending packet MESSAGE data 2["connected","testign"]
2b862ce363da4a76a8dd09ec9c422a9e: Sending packet MESSAGE data 2["connected","testign"]
ccf27e3a769949f7bda025baf6101650: Sending packet MESSAGE data 0
192.168.56.1 - - [15/Dec/2019 13:22:23] "GET /socket.io/?EIO=3&transport=polling&t=My9Iucn HTTP/1.1" 200 378 0.009000
Invalid session None
192.168.56.1 - - [15/Dec/2019 13:22:23] "POST /socket.io/?EIO=3&transport=polling&t=My9IudU HTTP/1.1" 400 186 0.007000
d685108dd3fe441799ed1f1aec0de32e: Sending packet OPEN data {'pingInterval': 25000, 'pingTimeout': 60000, 'upgrades': ['websocket'], 'sid': 'd685108dd3fe441799ed1f1aec0de32e'}
Client connected
50a596f672014296b90befb5cf69d139: Client is gone, closing socket
50a596f672014296b90befb5cf69d139: Client is gone, closing socket
a9b0114871554baea9cc33ea3637eccd: Sending packet MESSAGE data 2["connected","testign"]
0ddad6a7f8f6475ead11a8029ec04e0c: Sending packet MESSAGE data 2["connected","testign"]
6b42db33dded40e691ac074d2b0e08f3: Sending packet MESSAGE data 2["connected","testign"]
ccf27e3a769949f7bda025baf6101650: Sending packet MESSAGE data 2["connected","testign"]
d685108dd3fe441799ed1f1aec0de32e: Sending packet MESSAGE data 2["connected","testign"]
2b862ce363da4a76a8dd09ec9c422a9e: Sending packet MESSAGE data 2["connected","testign"]
d685108dd3fe441799ed1f1aec0de32e: Sending packet MESSAGE data 0
192.168.56.1 - - [15/Dec/2019 13:22:28] "GET /socket.io/?EIO=3&transport=polling&t=My9IvzR HTTP/1.1" 200 378 0.005000
Invalid session None
192.168.56.1 - - [15/Dec/2019 13:22:28] "POST /socket.io/?EIO=3&transport=polling&t=My9Ivzx HTTP/1.1" 400 186 0.001000
6f9d2c39e31a4cdb9f1c55a490772388: Sending packet OPEN data {'pingInterval': 25000, 'pingTimeout': 60000, 'upgrades': ['websocket'],