Amr Ashraf
Amr Ashraf

Reputation: 431

Listen for dropped connections on server sent event

I used SSE for push notification. But i can't get an error or a close event in the server when the client's wifi/mobile data unconditionally disconnect without closing the connection in the right way. It always see the client as online for about 15 minutes before getting connection closed message.

I used regular implementation of SSE in nodejs and express.

Is there any way to check response.write() whether the message delivered to the user or not?

Upvotes: 2

Views: 1643

Answers (1)

Darren Cook
Darren Cook

Reputation: 28968

To get a socket error you need the server to attempt to write data; there is no other way to detect when the connection has dropped except to try using it.

As described in chapter 5 of Data Push Apps with HTML5 SSE, what I do is: a) have the server send out a keep-alive message every e.g. 30 seconds. I normally have the message just be the current datestamp, but it could be anything; b) have the client disconnect and reconnect if it hasn't received any messages for 45 seconds.

Upvotes: 1

Related Questions