I want to get data in my Flask server from a socket.io client. My setting is:
- Client1 calls method request_data on server.
- The method request_data then emits 'client2' event on Client2.
I have the following method in my flask server:
@socketio.on('client1')
def test_message(message):
emit('client2', {'data': 'testdata'})
On the client that should receive the data:
$(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")
});
});
But I cannot seem to establish the connection to client2. What am I doing wrong here?