{"id":15655673,"url":"https://github.com/sacoo7/socketcluster-client-unity","last_synced_at":"2025-05-05T14:42:32.878Z","repository":{"id":79881362,"uuid":"140146948","full_name":"sacOO7/socketcluster-client-unity","owner":"sacOO7","description":"An extension to original C# client implementation.","archived":false,"fork":false,"pushed_at":"2018-07-30T06:37:02.000Z","size":27,"stargazers_count":23,"open_issues_count":2,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-17T06:46:15.131Z","etag":null,"topics":["client","socketcluster","unity","websocket"],"latest_commit_sha":null,"homepage":"https://socketcluster.io/","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/sacOO7.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-07-08T07:30:47.000Z","updated_at":"2024-11-06T20:44:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"2e5236d2-3f2c-47a2-bbe7-84d114fca0e3","html_url":"https://github.com/sacOO7/socketcluster-client-unity","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/sacOO7%2Fsocketcluster-client-unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sacOO7","download_url":"https://codeload.github.com/sacOO7/socketcluster-client-unity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252516200,"owners_count":21760742,"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":["client","socketcluster","unity","websocket"],"created_at":"2024-10-03T13:00:19.431Z","updated_at":"2025-05-05T14:42:32.842Z","avatar_url":"https://github.com/sacOO7.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# socketcluster-client-unity\nAn extension to original C# client implementation.\n=====================================\n\nOverview\n--------\nThis client provides following functionality\n\n- Support for emitting and listening to remote events\n- Automatic reconnection\n- Pub/sub\n- Authentication (JWT)\n\nClient supports following platforms\n\n- **Unity Desktop/Android/iOS**\n- .Net 2.0\n- .Net 3.5\n- .Net 4.0\n- .Net standard 1.5 onwards\n- .Net Core 1.0 onwards\n\nLicense\n-------\nApache License, Version 2.0\n\nUsage via Nuget\n------\n```\n    Install-Package ScClient.Unity\n```\n\nNuget Gallery link : https://www.nuget.org/packages/ScClient.Unity/\n\n\u003c!--Yet to be uploaded. --\u003e\n\nUsage using source files\n------\nLibrary is built on top of Websocket4Net and Newtonsoft.Json. Install those packages via nuget and add source\nfiles into project\n\nDescription\n-----------\nCreate instance of `Socket` class by passing url of socketcluster-server end-point\n\n```C#\n    //Create a socket instance\n    string url = \"ws://localhost:8000/socketcluster/\";\n    var socket = new Socket(url);\n\n```\n**Important Note** : Default url to socketcluster end-point is always *ws://somedomainname.com/socketcluster/*.\n\n\n#### Registering basic listeners\n\nCreate a class implementing `BasicListener` interface and pass it's instance to socket setListener method\n\n```C#\n\n        internal class MyListener : IBasicListener\n        {\n            public void OnConnected(Socket socket)\n            {\n                Console.WriteLine(\"connected got called\");\n            }\n\n            public void OnDisconnected(Socket socket)\n            {\n                Console.WriteLine(\"disconnected got called\");\n            }\n\n            public void OnConnectError(Socket socket, ErrorEventArgs e)\n            {\n                Console.WriteLine(\"on connect error got called\");\n            }\n\n            public void OnAuthentication(Socket socket, bool status)\n            {\n                Console.WriteLine(status ? \"Socket is authenticated\" : \"Socket is not authenticated\");\n            }\n\n            public void OnSetAuthToken(string token, Socket socket)\n            {\n                socket.setAuthToken(token);\n                Console.WriteLine(\"on set auth token got called\");\n            }\n\n        }\n\n        internal class Program\n        {\n            public static void Main(string[] args)\n            {\n                var socket = new Socket(\"ws://localhost:8000/socketcluster/\");\n                socket.SetListerner(new MyListener());\n            }\n        }\n\n\n```\n\n#### Connecting to server\n\n- For connecting to server:\n\n```C#\n    //This will send websocket handshake request to socketcluster-server\n    socket.Connect();\n```\n\n- By default reconnection to server is not enabled , to enable it :\n\n```C#\n    //This will set automatic-reconnection to server with delay of 3 seconds and repeating it for 30 times\n    socket.SetReconnectStrategy(new ReconnectStrategy().SetMaxAttempts(30));\n    socket.Connect()\n```\n\n- To disable reconnection :\n\n```\n   socket.SetReconnectStrategy(null);\n```\n\nEmitting and listening to events\n--------------------------------\n#### Event emitter\n\n- eventname is name of event and message can be String, boolean, Long or JSON-object\n\n```C#\n    socket.Emit(eventname,message);\n\n    //socket.Emit(\"chat\",\"Hi\");\n```\n\n- To send event with acknowledgement\n\n```C#\n\n    socket.Emit(\"chat\", \"Hi\", (eventName, error, data) =\u003e\n    {\n       //If error and data is String\n       Console.WriteLine(\"Got message for :\"+eventName+\" error is :\"+error+\" data is :\"+data);\n    });\n\n```\n\n#### Event Listener\n\n- For listening to events :\n\nThe object received can be String, Boolean, Long or JSONObject.\n\n```C#\n\n    socket.On(\"chat\", (eventName, data) =\u003e\n    {\n        Console.WriteLine(\"got message \"+ data+ \" from event \"+eventName);\n    });\n\n```\n\n- To send acknowledgement back to server\n\n```C#\n\n    socket.On(\"chat\", (eventName, data, ack) =\u003e\n    {\n        Console.WriteLine(\"got message \"+ data+ \" from event \"+eventName);\n        ack(name, \"No error\", \"Hi there buddy\");\n    });\n\n```\n\nImplementing Pub-Sub via channels\n---------------------------------\n\n#### Creating channel\n\n- For creating and subscribing to channels:\n\n```C#\n    var channel=socket.CreateChannel(channelName);\n   //var channel=socket.CreateChannel(\"yolo\");\n\n\n    /**\n     * without acknowledgement\n     */\n     channel.Subscribe();\n\n    /**\n     * with acknowledgement\n     */\n\n    channel.Subscribe((channelName, error, data) =\u003e\n    {\n       if (error == null)\n       {\n             Console.WriteLine(\"Subscribed to channel \"+channelName+\" successfully\");\n       }\n    });\n```\n\n- For getting list of created channels :\n\n```C#\n    List\u003cSocket.Channel\u003e channels = socket.GetChannels();\n```\n\n- To get channel by name :\n\n```C#\n    var channel=socket.GetChannelByName(\"yell\");\n    //Returns null if channel of given name is not present\n\n```\n\n#### Publishing event on channel\n\n- For publishing event :\n\n```C#\n       // message can have any data type\n    /**\n     * without acknowledgement\n     */\n     channel.Publish(message);\n\n    /**\n     * with acknowledgement\n     */\n       channel.Publish(message, (channelName, error, data) =\u003e\n       {\n            if (error == null) {\n               Console.WriteLine(\"Published message to channel \"+channelName+\" successfully\");\n            }\n       });\n\n```\n\n#### Listening to channel\n\n- For listening to channel event :\n\n```C#\n\n    //If instance of channel exists\n    channel.OnMessage((channelName, data) =\u003e\n    {\n         Console.WriteLine(\"Got message for channel \"+channelName+\" data is \"+data);\n    });\n\n    //or\n    socket.OnSubscribe(channelName, (channelName, data) =\u003e\n    {\n        Console.WriteLine(\"Got message for channel \"+channelName+\" data is \"+data);\n    });\n\n```\n\n\u003c!--###### Pub-sub without creating channel--\u003e\n#### Un-subscribing to channel\n\n```C#\n\n    /**\n     * without acknowledgement\n     */\n\n     channel.Unsubscribe();\n\n    /**\n     * with acknowledgement\n     */\n\n    channel.Unsubscribe((name, error, data) =\u003e\n    {\n        if (error == null) {\n            Console.WriteLine(\"channel unsubscribed successfully\");\n        }\n    });\n\n```\n\n#### Handling SSL connection with server\n\nTo enable or disable SSL certficate verification use\n```C#\n\nsocket.SetSSLCertVerification(true/false);\n\n```\n\n#### Setting HTTP proxy with server\n\n\n\n```C#\n\n//args, string : host , int : port\nsocket.SetProxy(host,port);\n\n```\n\n#### Star the repo. if you love the client :).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacoo7%2Fsocketcluster-client-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsacoo7%2Fsocketcluster-client-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacoo7%2Fsocketcluster-client-unity/lists"}