In web programming, one of the most important parts is the implementation of client and server communications. There are many libraries that can help programmers implement this step, and Socket IO is one of those application libraries. In this article we will learn what Socket io is and where to use it.
Table of Contents
What is the connection between the Client and the Server?
Before examining what Socket io is, it is important to know the relationship between the Client and the Server in web programming. Let’s first simplify the name of this library and examine what a socket is. Sockets are a kind of communication port of the web world and indicate the beginning and end of a connection in the Client-Server connection.
Sockets can be a stream of byte data that can be sent to a socket on the other side by writing information to them on one side, such as the client side. The second socket also has the ability to write new information and read incoming information.
So sockets are the main components in establishing a web-based communication and are present in the whole client-server communication process. When you open your browser and search on Google or go to a website, you are actually in the position of the applicant or client who has sent a request from his socket to the other side.
This request cannot reach Google or the site directly, but an interface called the server must do so. Therefore, your request is first sent to the server, then the server, by connecting to the destination site, takes the necessary data from the destination socket and responds to you. This is how all web connections are made, and programmers use libraries like Socket io to implement this connection.
What is a Web Socket?
Web Socket is a protocol that, along with HTTP protocols, allows two-way (Bidirectional) and real-time communication between the server and the client. Two-way communication means that the possibility of communication is supported and controlled by both the client and the server.
Timely communication is also defined in such a way that the user’s request is answered in the same period of time. The importance of this protocol is that it tries to maintain communication for a while, even in the intervals where information is not received and sent, and makes two-way communication possible.
In previous years, web communication was one-way. In this way, the client first registered the request and then the server tried to respond to it. But the ideal communication for programmers was one in which the server did not always wait for the client and could send the request independently.
The initial idea was to keep in touch after responding to the client, allowing the server to send its data. The problem with this type of communication was the increase in data overload and the delay in sending and receiving. Web sockets enabled stable, two-way communication with minimal latency and data overload. The protocol used by the Socket io library.
What is Socket io?
The library has two sections, including a server-side library for Node JS and a client-side library for the browser. Of course, this library has a section called Engine.io that manages two-way communication using the Web Socket protocol.
Socket.IO is also responsible for tracking and disconnecting, managing sent events and controlling messages. The Express JS framework is one of the frameworks used to build a web server and work with the Socket.IO library.
What are the features of Socket io?
This library has significant features such as:
This library also allows communication when proxies, antivirus or firewalls are enabled.
A mechanism for both parties to determine when a client or server is not responding.
The ability for users to make changes to documents and coordinate with other changes made by others.
Binary data streaming (Binary Streaming)
Sending data in byte form also allows you to send different types of data such as audio and video.