{"id":17705188,"url":"https://github.com/tom32i/netcode","last_synced_at":"2025-05-12T13:46:33.147Z","repository":{"id":55678737,"uuid":"143176806","full_name":"Tom32i/netcode","owner":"Tom32i","description":"Fast and efficient real-time communication websocket engine for multiplayer games in the browser.","archived":false,"fork":false,"pushed_at":"2023-10-24T05:25:43.000Z","size":424,"stargazers_count":14,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T08:01:38.706Z","etag":null,"topics":["gamedev","multiplayer","multiplayer-game","multiplayer-game-server","netcode","real-time","websocket","websockets"],"latest_commit_sha":null,"homepage":"","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/Tom32i.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-01T15:45:25.000Z","updated_at":"2024-06-25T15:44:41.546Z","dependencies_parsed_at":"2024-06-25T15:44:35.954Z","dependency_job_id":"c0daf167-ef8b-46e4-9636-c18ec1062ade","html_url":"https://github.com/Tom32i/netcode","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/Tom32i%2Fnetcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tom32i%2Fnetcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tom32i%2Fnetcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tom32i%2Fnetcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tom32i","download_url":"https://codeload.github.com/Tom32i/netcode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253750178,"owners_count":21958264,"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":["gamedev","multiplayer","multiplayer-game","multiplayer-game-server","netcode","real-time","websocket","websockets"],"created_at":"2024-10-24T22:07:06.184Z","updated_at":"2025-05-12T13:46:33.107Z","avatar_url":"https://github.com/Tom32i.png","language":"JavaScript","readme":"Netcode\n=======\n\n\u003e A simple JavaScript client \u0026 server binary-encoded websocket communication system aimed towards web video games development.\n\nFeatures:\n- 🔌 Server / Client duo, for node and the browser, that handle Websocket connection and communication.\n- ⚡️ Handle the binary encoding and decoding of your data, with performances in mind.\n- 📢 Listen for event dispatched over websocket with simple `on`/`off` event emitter system.\n- 💬 Fallback to JSON for easy debugging.\n\n## Requirements\n\n- Node \u003e= v8.0.0\n\n## Installation\n\n`npm add netcode`\n\n## Get started\n\n### Define a list of events\n\nThe server and the client __must__ share the same events.\nAn event is defined by its _unique_ name and the corresponding codec, responsible for encoding and decoding the data.\n\n```javascript\n// events.js\nimport Int8Codec from 'netcode/src/encoder/codec/Int8Codec';\nimport StringCodec from 'netcode/src/encoder/codec/StringCodec';\n\nexport default [\n\t['id', new Int8Codec()],\n\t['say', new StringCodec()],\n];\n```\n\nIn this example, the event list define how to send the following events over websocket:\n\n- `client.send('id', 255);`\n- `client.send('say', 'Hello world!');`\n\nThen you'll be able to listen to this events on the client as follow:\n\n- `client.on('id', id =\u003e { /* Do something */ });`\n- `client.on('say', sentence =\u003e { /* Do something */ });`\n\nNow let's create a server and an client that use this event list.\n\n### Setup a Server\n\nWe setup a server specifying the port and host on which the server will listen and the type of encoder to use.\nHere we use a BinaryEncoder to communicate in binary over websocket, with the previously configured event list.\n\n```javascript\nimport Server from 'netcode/src/server/Server';\nimport BinaryEncoder from 'netcode/src/encoder/BinaryEncoder';\nimport events from './events';\n\n// Listen on localhost:8080\nconst server = new Server(8080, 'localhost', new BinaryEncoder(events));\n\nserver.on('client:join', client =\u003e {\n\tclient.on('say', sentence =\u003e console.log(sentence));\n\tclient.send('id', client.id);\n});\n```\n\nNow we've got a server running at `localhost:8080` that listen for a `say` text event and send a `id` integer event to every client that connects.\n\n_See an [full example of server setup](demo-server.js)._\n\n### Write a Client\n\nNow we write a client, for the browser, that connects to our running server on `ws://localhost:8080` and use a BinaryEncoder with the same event list as the server.\n\n```javascript\nimport Client from 'netcode/src/client/Client';\nimport BinaryEncoder from 'netcode/src/encoder/BinaryEncoder';\nimport events from './events';\n\nconst client = new Client('ws://localhost:8080', new BinaryEncoder(events))\n\nclient.on('open', () =\u003e {\n\tclient.on('id', id =\u003e console.log(`My id is ${id}.`));\n\tclient.send('say', 'Hello world!');\n});\n```\n\nNow we've got client that listen for the `id` event and sent a sentence in a `say` event.\n\nConnection is alive and well!\n\n_See an [full example of client setup](demo-client.js)._\n\n## Complete documentation\n\nTo go further, see in-depth documentation and how-to's.\n\n- [Full API reference](doc/API.md).\n- [Default codecs and how-to write your own](doc/codecs.md).\n- [About packaging and setting up your own webpack configuration](doc/packaging.md).\n- [Use netcode over a custom domain name and/or secured SSL connection](doc/ssl.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom32i%2Fnetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftom32i%2Fnetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom32i%2Fnetcode/lists"}