我想从 socket.io 客户端获取我的 Flask 服务器中的数据。我的设置是:
- Client1 在服务器上调用方法 request_data。
- 然后方法 request_data 在 Client2 上发出“client2”事件。
我的烧瓶服务器中有以下方法:
@socketio.on('client1')
def test_message(message):
emit('client2', {'data': 'testdata'})
在应该接收数据的客户端上:
$(document).ready(function(){
var socket = io.connect('http://' + document.domain + ':'+location.port);
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
socket.on('client2', function(msg) {
console.log(msg.data)
console.log("here")
});
});
但我似乎无法建立与 client2 的连接。我在这里做错了什么?