{"id":13662392,"url":"https://github.com/endel/NativeWebSocket","last_synced_at":"2025-04-25T10:31:10.365Z","repository":{"id":37533270,"uuid":"200769444","full_name":"endel/NativeWebSocket","owner":"endel","description":"🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)","archived":false,"fork":false,"pushed_at":"2023-10-24T19:38:36.000Z","size":101,"stargazers_count":1240,"open_issues_count":53,"forks_count":158,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-10-29T17:11:57.977Z","etag":null,"topics":["unity-asset","unity3d-plugin","webgl","websockets"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/endel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"endel","patreon":"endel","open_collective":null,"ko_fi":"endeld","tidelift":null,"custom":"https://www.paypal.me/endeld"}},"created_at":"2019-08-06T03:27:58.000Z","updated_at":"2024-10-29T08:34:56.000Z","dependencies_parsed_at":"2024-01-11T17:42:35.842Z","dependency_job_id":"33eda098-3d80-4e98-adab-c4d0260da9d8","html_url":"https://github.com/endel/NativeWebSocket","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2FNativeWebSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2FNativeWebSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2FNativeWebSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2FNativeWebSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/endel","download_url":"https://codeload.github.com/endel/NativeWebSocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223996579,"owners_count":17238333,"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":["unity-asset","unity3d-plugin","webgl","websockets"],"created_at":"2024-08-02T05:01:57.435Z","updated_at":"2025-04-25T10:31:10.341Z","avatar_url":"https://github.com/endel.png","language":"C#","funding_links":["https://github.com/sponsors/endel","https://patreon.com/endel","https://ko-fi.com/endeld","https://www.paypal.me/endeld"],"categories":["NetWork","C#","C\\#"],"sub_categories":[],"readme":"\u003cimg src=\"Media/header.png?raw=true\" alt=\"Native WebSocket\" /\u003e\n\nThis is the simplest and easiest WebSocket library for Unity you can find!\n\n- No external DLL's required (uses built-in `System.Net.WebSockets`)\n- WebGL/HTML5 support\n- Supports all major build targets\n- Very simple API\n- (Used in [Colyseus Unity SDK](https://github.com/colyseus/colyseus-unity-sdk))\n\n### Consider supporting my work on [Patreon](https://patreon.com/endel) | [Ko-fi](https://ko-fi.com/endeld) | [PayPal](https://www.paypal.me/endeld)\n\n[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dendel%26type%3Dpatrons\u0026style=for-the-badge)](https://patreon.com/endel)\n\n## Installation\n\n*Requires Unity 2019.1+ with .NET 4.x+ Runtime*\n\n### Install via UPM (Unity Package Manager)\n1. Open Unity\n2. Open Package Manager Window\n3. Click Add Package From Git URL\n4. Enter URL: ```https://github.com/endel/NativeWebSocket.git#upm```\n\n### Install manually\n1. [Download this project](https://github.com/endel/NativeWebSocket/archive/master.zip)\n2. Copy the sources from `NativeWebSocket/Assets/WebSocket` into your `Assets` directory.\n\n## Usage\n\n```csharp\nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing NativeWebSocket;\n\npublic class Connection : MonoBehaviour\n{\n  WebSocket websocket;\n\n  // Start is called before the first frame update\n  async void Start()\n  {\n    websocket = new WebSocket(\"ws://localhost:3000\");\n\n    websocket.OnOpen += () =\u003e\n    {\n      Debug.Log(\"Connection open!\");\n    };\n\n    websocket.OnError += (e) =\u003e\n    {\n      Debug.Log(\"Error! \" + e);\n    };\n\n    websocket.OnClose += (e) =\u003e\n    {\n      Debug.Log(\"Connection closed!\");\n    };\n\n    websocket.OnMessage += (bytes) =\u003e\n    {\n      Debug.Log(\"OnMessage!\");\n      Debug.Log(bytes);\n\n      // getting the message as a string\n      // var message = System.Text.Encoding.UTF8.GetString(bytes);\n      // Debug.Log(\"OnMessage! \" + message);\n    };\n\n    // Keep sending messages at every 0.3s\n    InvokeRepeating(\"SendWebSocketMessage\", 0.0f, 0.3f);\n\n    // waiting for messages\n    await websocket.Connect();\n  }\n\n  void Update()\n  {\n    #if !UNITY_WEBGL || UNITY_EDITOR\n      websocket.DispatchMessageQueue();\n    #endif\n  }\n\n  async void SendWebSocketMessage()\n  {\n    if (websocket.State == WebSocketState.Open)\n    {\n      // Sending bytes\n      await websocket.Send(new byte[] { 10, 20, 30 });\n\n      // Sending plain text\n      await websocket.SendText(\"plain text message\");\n    }\n  }\n\n  private async void OnApplicationQuit()\n  {\n    await websocket.Close();\n  }\n\n}\n```\n\n# Demonstration\n\n**1.** Start the local WebSocket server:\n\n```\ncd Server\nnpm install\nnpm start\n```\n\n**2.** Open the `NativeWebSocket/Assets/WebSocketExample/WebSocketExampleScene.unity` on Unity and Run.\n\n\n## Acknowledgements\n\nBig thanks to [Jiri Hybek](https://github.com/jirihybek/unity-websocket-webgl).\nThis implementation is based on his work.\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendel%2FNativeWebSocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendel%2FNativeWebSocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendel%2FNativeWebSocket/lists"}