{"id":22937711,"url":"https://github.com/ladislavbohm/socket.io-client-core","last_synced_at":"2025-08-12T18:32:21.004Z","repository":{"id":50778001,"uuid":"246398902","full_name":"LadislavBohm/socket.io-client-core","owner":"LadislavBohm","description":"High-Performance Socket.IO client in C#","archived":false,"fork":false,"pushed_at":"2022-11-23T21:53:20.000Z","size":203,"stargazers_count":73,"open_issues_count":6,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-08T05:40:31.386Z","etag":null,"topics":["socket","socket-io","socket-io-client","socket-io-net","socketio","socketio-client"],"latest_commit_sha":null,"homepage":null,"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/LadislavBohm.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":"2020-03-10T20:15:18.000Z","updated_at":"2024-09-12T09:56:09.000Z","dependencies_parsed_at":"2023-01-23T13:30:52.698Z","dependency_job_id":null,"html_url":"https://github.com/LadislavBohm/socket.io-client-core","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LadislavBohm%2Fsocket.io-client-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LadislavBohm%2Fsocket.io-client-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LadislavBohm%2Fsocket.io-client-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LadislavBohm%2Fsocket.io-client-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LadislavBohm","download_url":"https://codeload.github.com/LadislavBohm/socket.io-client-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229699846,"owners_count":18109854,"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":["socket","socket-io","socket-io-client","socket-io-net","socketio","socketio-client"],"created_at":"2024-12-14T12:14:05.987Z","updated_at":"2024-12-14T12:14:06.691Z","avatar_url":"https://github.com/LadislavBohm.png","language":"C#","readme":"![](socket-io-logo.png)\n\n# socket.io client written in C\u0026#35;\n\nHigh-performance C# client for socket.io. Flexibility achieved via [Reactive Extensions](https://github.com/dotnet/reactive#reactive-extensions) and optional configurations. Built on top of .NET Standard 2.1.\n\n## Installation\n\n```\nPM\u003e Install-Package Socket.Io.Client.Core\n```\n\n## Features\n\n- Fully async and non-blocking flexible API\n- Emit events and receive optional callbacks\n- Subscribe/Unsubscribe to events\n- Monitor socket state\n  - React to various socket high/low-level events\n\n## Changelog\n\n- 1.1.0\n  - moved from Utf8Json to System.Text.Json (\u003cb\u003ebreaking change\u003c/b\u003e)\n  - fixed parsing of multiple arguments where some of them were not JSON serialized\n- 1.2.0\n  - added support for event message acknowledgements\n\n## Examples\n\nFor more examples see [test project](https://github.com/LadislavBohm/socket.io-client-core/tree/master/src/Socket.Io.Client.Core.Test).\n\nReal-world example can be found in my other repository - Crypto Compare streamer API client:\nhttps://github.com/LadislavBohm/cryptocompare-streamer\n\n### Open/Close Connection\n\n```csharp\n//socket is disposed using new \"using\" syntax, don't forget to dispose it!\nusing var client = new SocketIoClient();\n//optionally supply additional parameters using OpenOptions\nvar options = new SocketIoOpenOptions(\"custom-path\");\n\nawait client.OpenAsync(new Uri(\"http://localhost:3000\"), options);\nawait client.CloseAsync();\n```\n\n### Subscribe to built-in events\n\nEvents are implemented using Reactive Extensions, for more information see [here](https://github.com/dotnet/reactive#reactive-extensions) or a very nice [tutorial](http://introtorx.com/). However a very basic usage will be shown here.\n\n#### Basic subscriptions\n\n```csharp\nusing var client = new SocketIoClient();\n\n//no need to hold reference to subscription as it\n//will be automatically unsubscribed once client is disposed\nclient.Events.OnOpen.Subscribe((_) =\u003e\n{\n    Console.WriteLine(\"Socket has been opened\");\n});\n\n//subscribe to event with data\nclient.Events.OnPacket.Subscribe(packet =\u003e\n{\n    Console.WriteLine($\"Received packet: {packet}\");\n});\n\nawait client.OpenAsync(new Uri(\"http://localhost:3000\"));\n```\n\n#### Time-based subscriptions\n\n```csharp\nusing var client = new SocketIoClient();\n\n//in reality you shouldn't need to work directly with packets\nvar subscription = client.Events.OnPacket.Subscribe(packet =\u003e\n{\n    Console.WriteLine($\"Received packet: {packet}\");\n});\n\nawait client.OpenAsync(new Uri(\"http://localhost:3000\"));\n//let the subscription live for 500 milliseconds\nawait Task.Delay(500);\n//unsubscribe from this event (socket and other subscriptions are still running)\nsubscription.Dispose();\n```\n\n### Subscribe/Unsubscribe to custom events\n\nEvent data from socket.io are received as an array. In event data object you can access the whole array or for convenience just the first item (if available).\n\n```csharp\nusing var client = new SocketIoClient();\n\n//in this example we throttle event messages to 1 second\nvar someEventSubscription = client.On(\"some-event\")\n    .Throttle(TimeSpan.FromSeconds(1)) //optional\n    .Subscribe(message =\u003e\n{\n    Console.WriteLine($\"Received event: {message.EventName}. Data: {message.FirstData}\");\n});\n\nawait client.OpenAsync(new Uri(\"http://localhost:3000\"));\n\n//optionally unsubscribe (equivalent to off() from socket.io)\nsomeEventSubscription.Dispose();\n```\n\n### Acknowledgements\n\nYou can optionally send ACK to server when you receive a message. There is also option to send any data back to server.\n\n```csharp\nusing var client = new SocketIoClient();\n\nclient.On(\"messages\").Subscribe(e =\u003e\n{\n    //always check before calling acknowledgement\n    if (e.SupportsAcknowledge)\n    {\n        //without any data\n        e.Acknowledge();\n\n        //OR with any optional serializable data\n        e.Acknowledge(\"message has been processed\");\n    }\n});\n\n```\n\n### Emit message to server\n\nAll emitted messages have an optional callback (acknowledgement) possible via subscribing to the result of Emit method.\nAll operations are non-blocking and asynchronously handled by underlying Channel library.\n\n```csharp\nusing var client = new SocketIoClient();\n\nclient.Emit(\"some-event\"); //no data emitted\nclient.Emit(\"some-event\", \"some-data\"); //string data\nclient.Emit(\"some-event\", new {data = \"some-data\"}); //object data\n\n//with callback (acknowledgement)\n//it is always called only once, no need to unsubscribe/dispose\nclient.Emit(\"some-event\", \"some-data\").Subscribe(ack =\u003e\n{\n    Console.WriteLine($\"Callback with data: {ack.Data[0]}.\");\n});\n```\n\n### Configuration\n\n```csharp\n//optionally supply your own implementation of ILogger (default is NullLogger)\nvar options = new SocketIoClientOptions()\n    .With(logger: new NullLogger\u003cSocketIoClient\u003e());\n\nusing var client = new SocketIoClient(options);\n```\n\n## To-do\n\n- Binary data (no support yet)\n- Implement automatic reconnection (you can do it by yourself using currently available events)\n- Document source code\n\n## Inspiration and Thanks\n\nThanks to following people and libraries that I used as an inspiration or help during development.\n\n- https://github.com/Marfusios/websocket-client\n- https://github.com/socketio/socket.io-client-java\n- https://github.com/doghappy/socket.io-client-csharp\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladislavbohm%2Fsocket.io-client-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladislavbohm%2Fsocket.io-client-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladislavbohm%2Fsocket.io-client-core/lists"}