{"id":15132963,"url":"https://github.com/arfanabid/socket-basics","last_synced_at":"2026-02-25T07:09:30.948Z","repository":{"id":255318831,"uuid":"848974313","full_name":"ArfanAbid/Socket-Basics","owner":"ArfanAbid","description":"A repo for understanding the Socket/WebSocket and its implementation","archived":false,"fork":false,"pushed_at":"2024-08-29T13:16:10.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T21:45:21.172Z","etag":null,"topics":["socket-io","socket-programming"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArfanAbid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-28T18:40:11.000Z","updated_at":"2024-08-29T13:16:13.000Z","dependencies_parsed_at":"2024-09-26T04:42:04.095Z","dependency_job_id":null,"html_url":"https://github.com/ArfanAbid/Socket-Basics","commit_stats":null,"previous_names":["arfanabid/socket-basics"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArfanAbid%2FSocket-Basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArfanAbid%2FSocket-Basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArfanAbid%2FSocket-Basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArfanAbid%2FSocket-Basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArfanAbid","download_url":"https://codeload.github.com/ArfanAbid/Socket-Basics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406071,"owners_count":20933802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["socket-io","socket-programming"],"created_at":"2024-09-26T04:41:57.811Z","updated_at":"2026-02-25T07:09:30.901Z","avatar_url":"https://github.com/ArfanAbid.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Socket Basics\n\n#### Socket.io is a library of webSocket\n##### WebSocket is a communication protocol like HTTP/FTTP/SMTP\n\n- In HTTP, there are two components: Client and Server. The Client makes a request, upon which the Server responds, similar to how an API works. This is one-way communication.\n\n- In WebSocket, a connection is made between the Client and Server. Once the connection is established, the Server can send a response or message at any time without requiring a request from the Client.\n\n- WebSocket is a communication protocol that enables full-duplex (two-way) communication between a client and a server over a single, long-lived connection. Unlike HTTP, where communication is initiated by the client, WebSocket allows either the client or server to send messages at any time once the connection is established.\n\n### Sockets\n\n#### How Sockets Work\n##### Socket Types:\n\n-  **Stream Sockets (TCP):** These provide reliable, connection-oriented communication. They use the Transmission Control Protocol (TCP), ensuring that data is delivered in the correct order and without errors.\n- **Datagram Sockets (UDP):** These provide connectionless communication. They use the User Datagram Protocol (UDP), which is faster but does not guarantee reliable delivery or order of packets.\n\n#### Components\n- **io**: Refers to the entire server or circuit.\n- **socket**: Refers to one particular socket or client. Each socket has its own ID, allowing them to be differentiated.\n- One **io** can contain many sockets.\n\n#### Functions in Socket.io Library:\n\n- **Emit**: Used to send a message from the server to the client or vice versa. `socket.emit('event_name', data);`\n- **On**: Used to listen for a specific event and define what happens when that event occurs. `socket.on('event_name', callback);`\n- **Broadcast**: Used to send a message to all connected clients except the one that initiated the broadcast. `socket.broadcast.emit('event_name', data);` \n- **To**: Used to send a message to a specific room or group of sockets. `io.to('room_name').emit('event_name', data);`\n- **Join**: Allows a socket to join a specific room, enabling targeted messaging.`socket.join('room_name')`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farfanabid%2Fsocket-basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farfanabid%2Fsocket-basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farfanabid%2Fsocket-basics/lists"}