Web sockets and how they work

Foundation of web as we all know is based on Hypertext Transfer Protocol (HTTP) which uses request-response protocol. This, in a nutshell, means a web browser submits an HTTP request message to server and server which, holds resources, returns appropriate response message. However, servers weren’t allowed to send messages to browser because they couldn’t initiate a request. But many applications relied on real-time resources being sent to client from server such as messaging systems. It would be very annoying to ask user to click on a button so a request can be sent to server and latest data being received. Of course, writing an application that constantly send requests only creates overhead on network traffic and it is not efficient at all.

Hence, there was a need for a persistent connection between browser and server whereby both parties can send and receive data. Web sockets are solutions to maintain bidirectional communications with servers. But how do we make web sockets?

I’ve create a simple twitter app that sends and receives data to server which includes a html page that has a textbox, button and placeholder to present status of server responses.

You can download the Gist from my code repo or directly from Jsbin.

Ramin Ahmadi
I am a full-stack front end developer with over 5 years experience in web design and development. I have worked with a wide variety of environments and languages including Angular, TypeScript, NodeJS, Restful API, Microservices, Atomic design, JQuery, Material design, Progressive Web Apps, DevOps, and many Azure tools. I make it a goal to automate myself out of routine tasks in my daily work. My motto is, ‘write human readable code, lean and clean’.

Comments 0

Your email address will not be published. Required fields are marked *

Web sockets and how they work

log in


reset password

Back to
log in
Font Resize
Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Voting to make decisions or determine opinions
The Classic Internet Listicles
Photo or GIF
GIF format