Socket.io-client Connecting, But Not Emitting
I am making a little encrypted chat app, in the terminal, using socket.io-client and socket.io. The client is able to connect to the server, but is not emitting the username, when
Solution 1:
If you want to send events between client and server you have to:
Send event A from client to the server and server has to be listening for the A event.
If you want to send event B from server to client then client has to be listening for the event B.
Apart from everything else in your code I don't see where you are listening for the 'chat message' event on the client side.
Socket.io is based on these so called 'events'. The code below is going to send 'my_event' event to the server and the trasmitted data is going to be the object { a: 1 }.
socket.emit('my_event', { a: 1 });
If I want to handle this event on the server I have to listen for it:
socket.on('my_event', function(data) {
// data is the object { a: 1 }// do stuff..
});
Post a Comment for "Socket.io-client Connecting, But Not Emitting"