Can’t receive payload from emited event – Socket.io

the problem is that the event “connect” you emit is an already “reserved” event that is send from socket server when a socket is successfully connected.

Just do the following change

Rename the event e.x from “connect” to “connected” in both side (client and server) “Server” code

 socket.emit('connected', 'socket server is connected');

and on the “Client”

socket.on('connected', msg => {
  console.log(msg); //msg will no longer be "undefined"
});

and you will be ok

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top