Advantages of Websockets | disadvantages of Websockets
This page covers advantages and disadvantages of Websockets over HTTP used in IoT (Internet of Things). It mentions benefits or advantages of Websockets and drawbacks or disadvantages of Websockets.
What are Websockets?
Websockets is a technology for bidirectional communication over single (TCP) socket, a type of PUSH technology. It is a protocol which provides bidirectional, full duplex communication channels over a single TCP socket. It is designed to be implemented in web browsers and web servers, but it can be used by any client or server application.
The figure depicts messages exchanged between client and server. As shown websocket uses handshake messages to establish or open connection where as HTTP uses request-response messaging mechanism. HTTP is half duplex where as websocket is full duplex.
It is a protocol which enables developers to open a persistent connection and send data in realtime between a client and a server. Messages can be sent between the single TCP socket connection (simultaneously or back and forth).
Benefits or advantages of Websockets over HTTP
Following are the benefits or advantages of Websockets over HTTP:
➨It supports duplex communication.
➨Using websockets, one can send and receive data immediately faster than HTTP. Moreover they are faster than AJAX.
➨Cross origin communication (however this poses security risks).
➨Cross platform compatibility (web, desktop, mobile)
➨HTTP takes upto 2000 bytes of overhead where as websocket takes only 2 bytes.
➨Replace long polling
➨Websockets are data typed but AJAX calls can only send string datatypes.
Drawbacks or disadvantages of Websockets
Following are the drawbacks or disadvantages of Websockets:
➨Web browser must be fully HTML5 compliant.
➨Websockets has no success functions like AJAX.
➨Intermediary/Edge caching is not possible with websockets unlike HTTP.
➨To build even simple protocol of your own, one can not be able to use friendly HTTP statuses, body etc.
➨If application does not require a lot of dynamic interaction, HTTP is much simpler to implement.