What is Websocket?

Websockets are a sort of PUSH technology that allows bidirectional communication over a single (TCP) socket. It's a protocol that uses a single TCP socket to provide bidirectional, full-duplex communication channels. It was created with web browsers and servers in mind, but it can be used by any client or server program.
Messages between client and server are depicted in the diagram. Websockets use handshake messages to establish or open connections, whereas HTTP uses the request-response messaging mechanism. Websockets are full-duplex, while HTTP is half-duplex.
It's a protocol that allows programmers to create a permanent connection between a client and a server and send data in real-time. Messages can be transmitted between the TCP sockets of a single connection (simultaneously or back and forth).

What is the purpose of WebSocket?

The limitations of HTTP-based technology were the inspiration that brought about the development of WebSockets. A client will request a resource using HTTP, while the server will respond with the details. HTTP is a one-way protocol, which means that all data sent from the server to the client must be requested at first.
Long-polling has historically been used to get around this restriction. Long-polling is when a client sends an HTTP request with a long timeout, and the server uses the timeout to send data to the client. Long-polling works, but it has a drawback: it ties up server resources for the duration of the long poll, even though no data is available to submit.
WebSockets, in the other way round, allow the transmission of message-based data in a manner similar to UDP but with the security of TCP. WebSocket uses HTTP as the initial transport method but leaves the TCP link open after the HTTP response is received so that messages can be sent between client and server. WebSockets allow us to create “real-time” applications without requiring the use of long pollination.

Advantages of WebSocket 

Cons of Websocket

Pros of EventSource:

Cons of EventSource:

Conclusion

The classification of WebSockets as the model for data push and real-time communication is somewhat of a misnomer around the web as it is described nowadays. Independent of some open-source resolutions, WebSockets are just a part of the puzzle when developing real-time applications.
There is a slew of operational issues a developer may run into when using WebSockets as their real-time solution, particularly as the app scales and the user base grows technology like: Firewalls, Network topology, Load testing, and Security.