# Getting Started with Socket.IO: Building Real-Time Web Applications

DevFeed: [Getting Started with Socket.IO: Building Real-Time Web Applications](<https://devfeed.tech/articles/getting-started-with-socket-io-building-real-time-web-applications-26511.md>)

Original publisher: [Read original article](<https://medium.com/engineering-housing/getting-started-with-socket-io-building-real-time-web-applications-0bd5b9c303e2?source=rss----3a69e32e2594---4>)

Author: Jitendra Kumar

Published: 2024-06-12T06:49:56Z

Content type: tutorial

Language: en

Sources: [Housing.com](<https://devfeed.tech/sources/housing-com.md>)

Topics: [Socket.IO](<https://devfeed.tech/topics/socket-io.md>), [WebSocket](<https://devfeed.tech/topics/websocket.md>), [Node.js](<https://devfeed.tech/topics/node-js.md>), [HTTP](<https://devfeed.tech/topics/http.md>), [servers](<https://devfeed.tech/topics/servers.md>)

Tags: [client-library](<https://devfeed.tech/tags/client-library.md>), [event](<https://devfeed.tech/tags/event.md>), [http](<https://devfeed.tech/tags/http.md>), [latency](<https://devfeed.tech/tags/latency.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [real-time](<https://devfeed.tech/tags/real-time.md>), [server](<https://devfeed.tech/tags/server.md>), [web-applications](<https://devfeed.tech/tags/web-applications.md>), [websocket](<https://devfeed.tech/tags/websocket.md>)

## AI overview

This tutorial introduces Socket.IO as a Node.js server-side library for low-latency, bidirectional, event-based communication. It explains the client-server connection process, including the HTTP handshake, transport selection, optional upgrade to WebSocket, real-time messaging, and heartbeat keep-alive.

## Source excerpt

What is Socket.io ? Socket.IO is a server-side library for nodejs that enables low-latency, bidirectional and event-based communication between a client and a server using client-server architecture while it is a wrapper around WebSockets For Node.js, it is super easy and simple to use especially when dealing with chat messages or Real-time data. Socket Client-Server Architecture How persistent bi-directional connection is established between client(s) and server ? The connection process between a Socket.IO client and server involves several steps. Below is a detailed breakdown of the key steps: 1. Handshake Initialization: The client initiates a connection to the Socket.IO server by sending an HTTP request (often a GET request) to the server using constructor provided by socket-io.client library. // Connect to the server (URL is optional if both client and server are at same origin ) const socket = io('http://localhost:3000'); The request includes a specific path, typically /socket.io/, and it may also include query parameters indicating the supported Socket.IO protocol version (EIO=3), transports, and other details. Example : GET /socket.io/?EIO=3&transport=polling&t=timestamp 2. Server Handshake Response: The Socket.IO server receives the initial HTTP request and responds with a handshake. The response includes the selected transport mechanism and a unique session ID (sid) that will be used to identify the connection. 3. Connection Upgrade (Optional): If the client and server both support WebSocket and agree to use it, they may negotiate to upgrade the connection from HTTP to WebSocket. This is an optimization for more efficient and bidirectional communication. 4. Transport Initialization: Based on the handshake response, the client initializes the chosen transport (e.g., WebSocket, polling). If using WebSocket, a WebSocket connection is established directly. If using polling, the client may start polling the server for updates. 5. Real-Time Communication: Once t