{"id":25072406,"url":"https://github.com/lanfei/websocket-lib","last_synced_at":"2025-04-14T21:51:12.230Z","repository":{"id":35366501,"uuid":"39629364","full_name":"Lanfei/websocket-lib","owner":"Lanfei","description":"A lightweight WebSocket library for Node.","archived":false,"fork":false,"pushed_at":"2022-10-25T15:37:33.000Z","size":555,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T18:01:47.635Z","etag":null,"topics":["realtime","websocket","ws"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/websocket-lib","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lanfei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-24T11:32:32.000Z","updated_at":"2025-01-31T18:12:05.000Z","dependencies_parsed_at":"2023-01-15T19:22:14.937Z","dependency_job_id":null,"html_url":"https://github.com/Lanfei/websocket-lib","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lanfei%2Fwebsocket-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lanfei%2Fwebsocket-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lanfei%2Fwebsocket-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lanfei%2Fwebsocket-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lanfei","download_url":"https://codeload.github.com/Lanfei/websocket-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968741,"owners_count":21191158,"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":["realtime","websocket","ws"],"created_at":"2025-02-06T22:20:15.271Z","updated_at":"2025-04-14T21:51:12.211Z","avatar_url":"https://github.com/Lanfei.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node WebSocket Library\n\nThis is a lightweight WebSocket library for Node.\n\n[![NPM](https://nodei.co/npm/websocket-lib.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/websocket-lib)\n\n## Installation\n\n```bash\n$ npm install websocket-lib\n```\n\n### Documentation\n\n- [API documentation](https://github.com/Lanfei/websocket-lib/blob/master/docs/API.md)\n- [The WebSocket Protocol](https://tools.ietf.org/html/rfc6455)\n- [The WebSocket API by W3C](https://www.w3.org/TR/websockets/)\n\n## Examples\n\n### Server\n\n```js\nvar ws = require('websocket-lib');\n\nvar server = ws.createServer(function (session) {\n\tconsole.log('client connected');\n\n\tsession.on('data', function (data) {\n\t\tconsole.log('client msg:', data);\n\t\tthis.send('Hi, ' + data);\n\t});\n\n\tsession.on('close', function () {\n\t\tconsole.log('session closed');\n\t});\n});\n\nserver.listen(8000);\n```\n\n### Client\n\n```js\nvar ws = require('websocket-lib');\n\nvar client = ws.connect('ws://localhost:8000', function (session) {\n\n\tsession.setEncoding('utf8');\n\tsession.send('Client');\n\n\tsession.on('data', function (data) {\n\t\tconsole.log('server msg:', data);\n\t});\n\n\tsession.on('close', function () {\n\t\tconsole.log('session closed');\n\t});\n});\n```\n\n### Browser\n\n```js\nvar ws = new WebSocket('ws://localhost:8000');\nws.onmessage = function (event) {\n\tconsole.log('server msg:', event.data);\n};\nws.onclose = function () {\n\tconsole.log('session closed');\n};\nws.onopen = function () {\n\tws.send('Client');\n};\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flanfei%2Fwebsocket-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flanfei%2Fwebsocket-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flanfei%2Fwebsocket-lib/lists"}