Reputation: 7314
I have a JavaScript/html web socket client. It receives images from my server quite frequently. I am hosting my web socket server in a C# console application.
The longest my client has to wait for an image is 10 seconds.
Should I also be sending 'keep-alive' packets from my client (JavaScript) to my Server or is the fact that it receives regular data packets from my server enough?
Thanks
Upvotes: 1
Views: 106
Reputation: 35895
You can send ping messages from the server, and the client will answer with a pong message. It is part of the WebSocket protocol, not sure if your server implementation supports it. However, from the client you have no way to know if you got a ping message in while, so the client may be let hanging there.
Or you can do it at application level using your own messages. Basically create a "ping" message in JSON and send it regularly from the client to the server, then if you do not get a response in X time, reconnect.
If you don´t, the only problem is that the connection maybe half-open, and your client may be hanging there waiting for a image that will never come.
Cheers.
Upvotes: 1