DEV Community

Cover image for WebSockets protocol: Innovating your projects with efficiently live communication.
Lucas Reis
Lucas Reis

Posted on

WebSockets protocol: Innovating your projects with efficiently live communication.

Presentation

Hello, my name is Lucas Reis, I am 19 years old and a Software Engineering student at UNIEvangélica de Goiás, Brazil. To understand this article, it is recommended that you have some knowledge about Network Protocols and how Web works at background.

I am here to introduce you to a powerful network protocol that can enhance your projects - WebSockets.

What is WebSockets?

WebSocket is, at its core, an application protocol, similar to HTTP or FTP. The main difference is that in these other protocols, communication ends after a request-response interaction, while in WebSockets, the communication persists until one of the sides closes the channel. See the diagram below:

WebSockets message diagram

Origin

This protocol is built on top of TCP/IP, just like HTTP, but it can also be used in conjunction with HTTP to establish an initial connection between the client and server. Its origins can be traced back to December 2011, when the web was transitioning to Web 2.0, the web of interactions. With this protocol, it has been possible to create real-time applications such as web chats, video games, and more.

Handshake HTTP Sample

Screenshot from RFC 6455

What can this be helpful?

WebSockets can be extremely useful in certain situations where you need persistent and bidirectional real-time communication. In such contexts, it can be the best way to create an application that meets these requirements.

Application Sample

1. Webchat
You can use WebSockets to easily develop a real-time web chat!

2. Tracker
A Tracker can be developed using WebSockets to communicate in real-time between the front-end that sends coordinates to the back-end every 5 seconds or something similar.

3. Notifications
You can use WebSockets to communicate with the client that they have a new update without the need to reload the page or retrieve a specific endpoint with new notifications.

4. Video Games
Video Games can be developed using WebSockets as a Framework! It can enable instant communication between players and the server on the web without losing packets or causing lag.

The end!

This protocol is a great way to innovate your projects and show your friends that you know how to use TCP/IP to its full potential without sacrificing network performance! You are welcome to make suggestions for this article or correct any errors. =D

References

Top comments (0)