If I have a websocket connection open between a server and a desktop client, is it true that there is no data or bandwidth being used or exchanged between the two except for when I explicitly send some? And if that is true, does that mean I could essentially have thousands of open connections on a server at a time so long as data was only being transferred very infrequently?
Do open websockets use bandwidth or other resources?
Asked Answered
Technically yes. Although the WebSocket protocol has ping/pong frames, and the any of the two ends can send pings periodically and expect pongs as answers, otherwise the would kill the connection.
It would be a very bad idea not implement a "keep alive" mechanism, you won't be able of tell which connections are actually connected or improperly closed.
http://blog.stephencleary.com/2009/05/detection-of-half-open-dropped.html
Some of us believe keepalives are a big wart on TCP, making it unnecessarily fragile on low-bandwidth, low-reliability links (e.g., amateur satellite communications). –
Faircloth
Don't forget non-bandwidth resources. On most systems, an open TCP connection (e.g., a WebSocket) consumes a variety of limited resources, even with no packet traffic. Buffer memory and connection control blocks are the most common, but in some systems, port numbers also. –
Faircloth
Ping/pong frames can be as small as two bytes, and to have thousands of connections with little activity is not problem for any modern computer. I do performance testing with thousands of them on my laptop as server. Because mobile devices can lose connection without properly closing the connection, is recommendable to have the keep alive mechanism. –
Benn
What about on a cloud server that charges for outgoing bandwidth? –
Bavaria
© 2022 - 2024 — McMap. All rights reserved.