{"id":22462936,"url":"https://github.com/ashutosh7i/learning_websockets","last_synced_at":"2026-03-19T22:58:37.518Z","repository":{"id":191771539,"uuid":"685250558","full_name":"ashutosh7i/Learning_WebSockets","owner":"ashutosh7i","description":"A quick note on webSockets and Tutorial.","archived":false,"fork":false,"pushed_at":"2023-08-31T04:11:27.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-13T07:43:55.874Z","etag":null,"topics":["learning-resources","websocket-chat","websocket-client","websocket-server","websockets"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/ashutosh7i.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}},"created_at":"2023-08-30T20:34:42.000Z","updated_at":"2023-08-31T04:13:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"6f714ab1-4f80-466d-aec5-8fbb0298dc9e","html_url":"https://github.com/ashutosh7i/Learning_WebSockets","commit_stats":null,"previous_names":["ashutosh7i/learning_websockets"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ashutosh7i/Learning_WebSockets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutosh7i%2FLearning_WebSockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutosh7i%2FLearning_WebSockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutosh7i%2FLearning_WebSockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutosh7i%2FLearning_WebSockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashutosh7i","download_url":"https://codeload.github.com/ashutosh7i/Learning_WebSockets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutosh7i%2FLearning_WebSockets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29128711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T18:31:02.507Z","status":"ssl_error","status_checked_at":"2026-02-05T18:29:43.962Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["learning-resources","websocket-chat","websocket-client","websocket-server","websockets"],"created_at":"2024-12-06T09:11:46.029Z","updated_at":"2026-02-05T18:32:26.307Z","avatar_url":"https://github.com/ashutosh7i.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learning_WebSockets\n\n## What are WebSockets?\n\nWhen you need continuous data from a server, two approaches come to mind:\n1. Frequent API calls to request data (Polling)\n2. Utilizing WebSockets\n\nA WebSocket is a communication protocol that enables seamless and continuous interaction between clients and servers. It offers various communication patterns, including:\n- Client to Server (e.g., submitting a new post)\n- Server to Client (e.g., notifying about likes/views)\n- Server to Multiple Clients (e.g., broadcasting updates)\n\nWebSocket connections maintain a persistent, bidirectional link for ongoing communication.\n\n## How WebSockets Work\n\nUnlike traditional HTTP connections, where a client sends a request and waits for a response, WebSocket connections remain open. This persistence allows continuous data exchange between clients and servers until either side decides to terminate the connection. This is akin to a publish-subscribe messaging pattern, where clients \"subscribe\" to updates, and servers \"publish\" messages to subscribers.\n\n### Advantages\n\n1. **Single Connection**: Only one request-response is needed to establish a connection.\n2. **Stateful Connection**: WebSockets can maintain connection state, keeping track of data sent between client and server without relying on cookies or session IDs.\n\nThe WebSocket protocol serves two primary purposes:\n1. Opening a handshake.\n2. Facilitating data transfer.\n\n## Getting Started with WebSockets in Node.js\n\nTo demonstrate WebSocket usage in Node.js, i've made two files: `server` and `client`.\n\n### Client\n\nThe client-side HTML contains a textarea for input and a send button to communicate with the server. When the page loads, it establishes a WebSocket connection with the server.\n\n### Server\n\nThe server-side JavaScript uses the ws module to create a WebSocket server. It handles incoming connections, manages messages, and responds conditionally to specific inputs.\n\n```\n// server.js\nconst WebSocketServer = require(\"ws\");\nconst wss = new WebSocketServer.Server({ port: 8080 });\n\nwss.on(\"connection\", (ws) =\u003e {\n  // WebSocket server logic\n});\n```\n\n### Usage\n1. Run your WebSocket server using node main.js.\n2. Open client.html in a browser to interact with the WebSocket server.\n3. Input text, click \"Send,\" and observe the interactions in the browser console and terminal.\n\n### Conclusion\nWebSockets offer a powerful solution for real-time communication between clients and servers. By maintaining a persistent connection, WebSockets enable efficient data exchange, making them ideal for applications requiring continuous updates or instant notifications.\n\nThis was a basic project for me to learn and implement WebSockets\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashutosh7i%2Flearning_websockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashutosh7i%2Flearning_websockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashutosh7i%2Flearning_websockets/lists"}