{"id":14960440,"url":"https://github.com/rageagainstthepixel/com.utilities.websockets","last_synced_at":"2025-10-24T18:31:39.765Z","repository":{"id":239508974,"uuid":"767557143","full_name":"RageAgainstThePixel/com.utilities.websockets","owner":"RageAgainstThePixel","description":"A simple websocket plugin for Unity (UPM)","archived":false,"fork":false,"pushed_at":"2024-11-05T02:11:58.000Z","size":94,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-31T03:37:42.440Z","etag":null,"topics":["unity","unity-upm","unity3d","unity3d-plugin","upm","upm-package","websocket","websocket-client","websockets"],"latest_commit_sha":null,"homepage":"","language":"C#","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/RageAgainstThePixel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"StephenHodgson","patreon":"RageAgainstThePixel"}},"created_at":"2024-03-05T14:07:03.000Z","updated_at":"2024-11-05T02:11:17.000Z","dependencies_parsed_at":"2024-08-19T01:55:21.509Z","dependency_job_id":"9be706b1-ca6d-46cf-8623-e1e05ac02663","html_url":"https://github.com/RageAgainstThePixel/com.utilities.websockets","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"52123165ab90067b1c0ebe9a93b3667d9048b837"},"previous_names":["rageagainstthepixel/com.utilities.websockets"],"tags_count":2,"template":false,"template_full_name":"RageAgainstThePixel/upm-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RageAgainstThePixel%2Fcom.utilities.websockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RageAgainstThePixel%2Fcom.utilities.websockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RageAgainstThePixel%2Fcom.utilities.websockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RageAgainstThePixel%2Fcom.utilities.websockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RageAgainstThePixel","download_url":"https://codeload.github.com/RageAgainstThePixel/com.utilities.websockets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238024405,"owners_count":19403836,"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","unity-upm","unity3d","unity3d-plugin","upm","upm-package","websocket","websocket-client","websockets"],"created_at":"2024-09-24T13:22:17.532Z","updated_at":"2025-10-24T18:31:39.746Z","avatar_url":"https://github.com/RageAgainstThePixel.png","language":"C#","funding_links":["https://github.com/sponsors/StephenHodgson","https://patreon.com/RageAgainstThePixel"],"categories":[],"sub_categories":[],"readme":"# com.utilities.websockets\n\n[![Discord](https://img.shields.io/discord/855294214065487932.svg?label=\u0026logo=discord\u0026logoColor=ffffff\u0026color=7389D8\u0026labelColor=6A7EC2)](https://discord.gg/xQgMW9ufN4) [![openupm](https://img.shields.io/npm/v/com.utilities.websockets?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.utilities.websockets/) [![openupm](https://img.shields.io/badge/dynamic/json?color=brightgreen\u0026label=downloads\u0026query=%24.downloads\u0026suffix=%2Fmonth\u0026url=https%3A%2F%2Fpackage.openupm.com%2Fdownloads%2Fpoint%2Flast-month%2Fcom.utilities.websockets)](https://openupm.com/packages/com.utilities.websockets/)\n\nA simple websocket package for the [Unity](https://unity.com/) Game Engine.\n\n## Installing\n\nRequires Unity 2021.3 LTS or higher.\n\nThe recommended installation method is though the unity package manager and [OpenUPM](https://openupm.com/packages/com.utilities.websockets).\n\n### Via Unity Package Manager and OpenUPM\n\n#### Terminal\n\n```terminal\nopenupm add com.utilities.websockets\n```\n\n#### Manual\n\n- Open your Unity project settings\n- Select the `Package Manager`\n![scoped-registries](Utilities.Websockets/Packages/com.utilities.websockets/Documentation~/images/package-manager-scopes.png)\n- Add the OpenUPM package registry:\n  - Name: `OpenUPM`\n  - URL: `https://package.openupm.com`\n  - Scope(s):\n    - `com.utilities`\n- Open the Unity Package Manager window\n- Change the Registry from Unity to `My Registries`\n- Add the `Utilities.Websockets` package\n\n### Via Unity Package Manager and Git url\n\n\u003e [!WARNING]\n\u003e This repo has dependencies on other repositories! You are responsible for adding these on your own.\n\n- Open your Unity Package Manager\n- Add package from git url: `https://github.com/RageAgainstThePixel/com.utilities.websockets.git#upm`\n  - [com.utilities.async](https://github.com/RageAgainstThePixel/com.utilities.async)\n\n---\n\n## Documentation\n\n### Table Of Contents\n\n- [Connect to a Server](#connect-to-a-server)\n- [Handling Events](#handling-events)\n  - [OnOpen](#onopen)\n  - [OnMessage](#onmessage)\n  - [OnError](#onerror)\n  - [OnClose](#onclose)\n- [Sending Messages](#sending-messages)\n  - [Text](#sending-text)\n  - [Binary](#sending-binary)\n- [Disconnect from a Server](#disconnect-from-a-server)\n\n### Connect to a Server\n\nTo setup a new connection, create a new instance of WebSocket and subscribe to event callbacks, and call `Connect` or `ConnectAsync` methods.\n\n\u003e [!IMPORTANT]\n\u003e WebSocket implements `IDisposable` and should be properly disposed after use!\n\n```csharp\nvar address = \"wss://echo.websocket.events\";\nusing var socket = new WebSocket(address);\nsocket.OnOpen += () =\u003e Debug.Log($\"Connection Established @ {address}\");\nsocket.OnMessage += (dataFrame) =\u003e {\n    switch (dataFrame.Type)\n    {\n        case OpCode.Text:\n            AddLog($\"\u003c- Received: {dataFrame.Text}\");\n            break;\n        case OpCode.Binary:\n            AddLog($\"\u003c- Received: {dataFrame.Data.Length} Bytes\");\n            break;\n    }\n};\nsocket.OnError += (exception) =\u003e Debug.LogException(exception);\nsocket.OnClose += (code, reason) =\u003e Debug.Log($\"Connection Closed: {code} {reason}\");\nsocket.Connect();\n```\n\n\u003e [!NOTE]\n\u003e `socket.ConnectAsync()` is blocking until the connection is closed.\n\n### Handling Events\n\nYou can subscribe to the `OnOpen`, `OnMessage`, `OnError`, and `OnClose` events to handle respective situations:\n\n#### OnOpen\n\nEvent triggered when the WebSocket connection has been established.\n\n```csharp\nsocket.OnOpen += () =\u003e Debug.Log(\"Connection Established!\");\n```\n\n#### OnMessage\n\nEvent triggered when the WebSocket receives a message. The callback contains a data frame, which can be either text or binary.\n\n```csharp\nsocket.OnMessage += (dataFrame) =\u003e {\n    switch (dataFrame.Type)\n    {\n        case OpCode.Text:\n            AddLog($\"\u003c- Received: {dataFrame.Text}\");\n            break;\n        case OpCode.Binary:\n            AddLog($\"\u003c- Received: {dataFrame.Data.Length} Bytes\");\n            break;\n    }\n};\n```\n\n#### OnError\n\nEvent triggered when the WebSocket raises an error. The callback contains an exception which can be handled, re-thrown, or logged.\n\n```csharp\nsocket.OnError += (exception) =\u003e Debug.LogException(exception);\n```\n\n#### OnClose\n\nEvent triggered when the WebSocket connection has been closed. The callback contains the close code and reason.\n\n```csharp\nsocket.OnClose += (code, reason) =\u003e Debug.Log($\"Connection Closed: {code} {reason}\");\n```\n\n### Sending Messages\n\n#### Sending Text\n\nPerfect for sending json payloads and other text messages.\n\n```csharp\nawait socket.SendAsync(\"{\\\"message\\\":\\\"Hello World!\\\"}\");\n```\n\n#### Sending Binary\n\nPerfect for sending binary data and files.\n\n```csharp\nvar bytes = System.Text.Encoding.UTF8.GetBytes(\"Hello World!\");\nawait socket.SendAsync(bytes);\n```\n\n### Disconnect from a Server\n\nTo disconnect from the server, use `Close` or `CloseAsync` methods and dispose of the WebSocket.\n\n```csharp\nsocket.Close();\nsocket.Dispose();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frageagainstthepixel%2Fcom.utilities.websockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frageagainstthepixel%2Fcom.utilities.websockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frageagainstthepixel%2Fcom.utilities.websockets/lists"}