You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you emit from server, you should emit either a string or a json. In your case, the second parameter of emit is a function.
When you setup a listener on client (emit.on, in js), the second argument is a callback, which is a function that receives the data sent from server. What you're doing is trying to call this data as a function, which will not work.
Try this code:
server:
$socket->emit('test', 'Message sent from server!);
client:
socket.on('test', (data) => {
console.log('Message received in client:');
console.log(data);
});
Alternatively, you could try defining this callback and passing it to the listener, like this:
function callback (data) {
console.log('Message received in client:');
console.log(data);
}
socket.on('test', callback);
I'm trying to do something like:
And then on client side (v2.3.1):
But client shows empty object and nothing happening.
P.S. In reverse way it works fine (if emit from client and then trigger callback on server).
The text was updated successfully, but these errors were encountered: