Build real-time web applications using WebSockets!
What is the WebSocket?
WebSocket is a bi-directional communication protocol. Communication provides over a single TCP connection.
Thanks to the WebSocket protocol server and client can communicate in real-time.
Where can we use WebSockets?
There are many cases to use WebSocket
- Chat Applications
- Location Tracking
- Game Development
- Collaborative Apps
- Trade and Cryptocurrency Apps
What is the difference between HTTP and WebSocket Connection?
- HTTP is unidirectional, and WebSocket is bi-directional.
- When you send an HTTP request connection will close after getting a response but when you connect over WebSocket and send data to the server, the connection will still be alive.
- WebSocket is faster than HTTP.
- HTTP is stateless and opens a new connection for each request, but WebSocket can communicate over a single connection.
Some WebSocket Libraries
SocketIO : Very popular socket library => github.com/socketio
WS: github.com/websockets/ws
SockJS : github.com/sockjs/sockjs-client
Feathers: github.com/feathersjs/feathers
SocketCluster: github.com/SocketCluster/socketcluster
WebSocket Alternatives
Short Polling: send and receive requests at specific time intervals (every x seconds)
Long Polling: send and receive requests at specific time intervals but the server will keep the requests open until the timeout. If the server finds something it will respond (timeout 5 seconds, server found something in 2 seconds. It will respond).
Server-Sent Events: SSE is a uni-directional communication channel from server to client only. Server-Sent Events allow receiving data without polling. A client subscribes to a “stream” from a server and the server will send messages to the “event stream”. Mostly used for push notifications.
BONUS
Spring Boot & SocketIO & Reactjs — Chat application
github.com/gurkanucar/socketio-simple-chat
Res:
- https://en.wikipedia.org/wiki/WebSocket
- https://www.wallarm.com/what/a-simple-explanation-of-what-a-websocket-is
- https://www.geeksforgeeks.org/what-is-web-socket-and-how-it-is-different-from-the-http/
- https://socket.io/
- https://blog.bitsrc.io/8-node-js-web-socket-libraries-for-2018-818e7e5b67cf
- https://nexocode.com/blog/posts/websockets-friend-or-foe/