Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket data consumption

I'm currently studying for a project involving a web-server and some raspberrys. The challenge would basically be to watch raspberry "status" on a web interface.

Raspberrys are connected to the Internet through a GSM connection (mostly 3G). I'm developping using Node.js on both the clients and the server, and I'd like to use websockets through socket.io in order to watch the raspberry connection status (actually, this is more like watching the raspberry capability to upload data through my application), dealing with "connected" and "disconnected" events.

Would an always-alive websocket connection be reliable for such a use-case? Are websocket designed-to (or reliable-for) staying opened? Since this is a hard-testable situation, does anyone know a data-consumption estimate for an always-alive websocket? If I'm going in a wrong way, does anyone ever worked on such a use-case via another reliable way?

like image 349
Cyril CHAPON Avatar asked Feb 18 '15 09:02

Cyril CHAPON


People also ask

Are WebSockets efficient?

The WebSocket Protocol establishes full-duplex, bidirectional communication between a client and server. This two-way flow is unique to WebSocket connections, and it means they can transfer data very quickly and efficiently.

What are the disadvantages of WebSockets?

The biggest downside to using WebSocket is the weight of the protocol and the hardware requirements that it brings with it. WebSocket requires a TCP implementation, which may or may not be a problem, but it also requires an HTTP implementation for the initial connection setup.

Are WebSockets faster than API?

Websocket is distinct from http. As http is half-duplex which means communication can be from either sides(client and server) but not at same time. Websocket is said to be faster than http because it provides full duplex communication. So, both client and server can communicate at the same time.

Is WebSocket more efficient than HTTP?

All the frequently updated applications used WebSocket because it is faster than HTTP Connection. When we do not want to retain a connection for a particular amount of time or reuse the connection for transmitting data; An HTTP connection is slower than WebSockets.


1 Answers

Would an always-alive WebSocket connection be reliable for such a use-case ? Are WebSocket designed-to (or reliable-for) staying opened ?

Yes, WebSocket was designed to stay open and yes it's reliable for your use-case, a WebSocket connection is just a TCP connection which transmits data in frames.

Since this is a hard-testable situation, does anyone know an data-consumption estimate for an always-alive websocket ?

As I wrote, data in WebSocket connections is transmitted using frames, each frame has a header and the payload. The data sent from the client to the server is always masked and like this adds 4 bytes (the masking key) to each frame. The length of the header depends on the payload length:

  1. 2 bytes header for <=125 bytes payload
  2. 4 bytes header for <=65535 bytes payload
  3. 10 bytes header for <=2^64-1 bytes payload (rarely used)

Base Framing Protocol: https://www.rfc-editor.org/rfc/rfc6455#section-5.2

To keep the connection open, the server sends at a specific timeout (depends on the implementation, usually ~30 seconds) ping frames which are 2-127 bytes long, usually 2 bytes (only the header, without payload) and the client responds with pong frames which are also 2-127 bytes long.

like image 193
micnic Avatar answered Sep 20 '22 23:09

micnic