uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.85k stars 570 forks source link

What is the purpose of ping pong mechanism ? #475

Closed Adidi closed 3 years ago

Adidi commented 3 years ago

I have a flutter client application that connected to uwebsockets.js server and everything works fine. In flutter (I guess also in the websocket spec) you can define pingInterval which sends ping message every [interval] timeframe. So if I construct my server with idleTimeout the pingInterval will create the keep alive effect My question is why do i need it ? is it a bad practice for the server to not have idleTimeout and always stay connected to the client ?

Thanks

ghost commented 3 years ago

"Bad practice" is putting it lightly ;D

If the server has no timeout whatsoever it will just hang on to irrelevant resources forever. There is no guarantee RST or FIN packets will reach the server and there is no guarantee the client will ever send those. That's why a timeout is needed.

In v19 this whole thing will be entirely automatic but you still need to specify idleTimeout.

Adidi commented 3 years ago

Thanks ! Amazing job Alex on this lib. I am building a product that needed chat application - I worked with several commercial solution like pubnub and pusher and it was horrible experience.

Your library so far - although very low level - just seems to work perfectly. Kudos !