0

I'm wondering if it's possible to emit something, in the 'disconnect' handler on server-side before the connection is actually cut or if it's already too late (in case the client disconnected, and in case the server disconnected).

Cause I have a second thread that produces responses and I'd like to be able to send the last one at this time.

If it's not possible this way, but there is another way, I'd love to hear about that

Cheers

Valentin Coudert
  • 1,759
  • 3
  • 19
  • 44

1 Answers1

0

If the disconnect was triggered by the client, then by the time you get the callback it is already too late, the client is gone at that point.

If the disconnect is triggered by the server (i.e. your application), then you are free to emit one last thing before you call the disconnect() function. If you have a background thread that needs to emit something before the main thread disconnects the client, then you can use an Event or similar thread coordination strategy to make sure that the disconnect happens after the emit.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152