If the client emit some msg to the server, is there any way for client to know if this emit is failed or not ?
I think it my be some callback like :
socket.emit("test",dataToSend,function(err){ });
If the client emit some msg to the server, is there any way for client to know if this emit is failed or not ?
I think it my be some callback like :
socket.emit("test",dataToSend,function(err){ });
You can configure the server to listen for test
event, and emit back a test succeeded
event.
socket.on("test", function(data) {
socket.emit("test succeeded", data);
});
This way you can listen for successfully received test
events like so:
socket.on('test succeeded', function(data) {});
If you want to be notified on errors, send your function as the third argument.
// client
socket.emit("test", dataToSend, function(err, success) {
});
Then, on the server
socket.on("test", function(dataReceived, callback) {
});
on server
io.on('connect', (socket) => {
socket.on('join-room', ( user, handleError ) => {
//process data with user
let error = 'can not find user'
return handleError(error )
}
}
on client
socket.emit('join-room', user, error => {
console.log(error) //error from Server is here
}