简体   繁体   中英

Socket.io socket.emit ack never runs

From the docs, if you emit an event and pass a function, you should see the callback run.When I debug, this anonymous function never runs.

socket.emit('ferret', 'tobi', function (data) {
  console.log(data); // never called
});

However

socket.on('ferret', function(data){
      console.log(data); // data 
})
socket.emit('ferret');

So the event listener works, but the emit callback does not..

The callback don't automatically get called when you emit a message, it has to be evoked by the server, so on on your service side you need to do something like:

socket.on('ferret', function(data, callback) {
   //Process data
   callback(newData)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM