{"id":15645756,"url":"https://github.com/sacoo7/socketcluster-client-go","last_synced_at":"2025-09-02T13:41:47.947Z","repository":{"id":48333081,"uuid":"104928537","full_name":"sacOO7/socketcluster-client-go","owner":"sacOO7","description":"GO client for socketcluster","archived":false,"fork":false,"pushed_at":"2023-12-12T17:32:01.000Z","size":53,"stargazers_count":56,"open_issues_count":8,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T16:34:08.918Z","etag":null,"topics":["golang","gorilla","socketcluster-client","websocket"],"latest_commit_sha":null,"homepage":"https://socketcluster.io/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","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":"2017-09-26T19:25:32.000Z","updated_at":"2025-02-19T01:24:27.000Z","dependencies_parsed_at":"2024-06-18T18:21:08.243Z","dependency_job_id":"6e55d58c-8687-41d7-a129-90b58f21050f","html_url":"https://github.com/sacOO7/socketcluster-client-go","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sacOO7/socketcluster-client-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sacOO7","download_url":"https://codeload.github.com/sacOO7/socketcluster-client-go/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2Fsocketcluster-client-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273293700,"owners_count":25079892,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","gorilla","socketcluster-client","websocket"],"created_at":"2024-10-03T12:09:45.346Z","updated_at":"2025-09-02T13:41:47.904Z","avatar_url":"https://github.com/sacOO7.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# socketcluster-client-go\nRefer examples for more details :\n    \nOverview\n--------\nThis client provides following functionality\n\n- Easy to setup and use\n- Support for emitting and listening to remote events\n- Pub/sub\n- Authentication (JWT)\n- Can be used for testing of all server side functions\n\nTo install use\n\n```markdown\n    go get github.com/sacOO7/socketcluster-client-go/scclient\n```\n\nDescription\n-----------\nCreate instance of `scclient` by passing url of socketcluster-server end-point \n\n```go\n    //Create a client instance\n    client := scclient.New(\"ws://192.168.100.11:8000/socketcluster/\");\n    \n```\n**Important Note** : Default url to socketcluster end-point is always *ws://somedomainname.com/socketcluster/*.\n\n#### Registering basic listeners\n \nDifferent functions are given as an argument to register listeners\n\n```go\n        package main\n        \n        import (\n        \t\"github.com/sacOO7/socketcluster-client-go/scclient\"\n        \t\"text/scanner\"\n        \t\"os\"\n        \t\"fmt\"\n        )\n        \n        func onConnect(client scclient.Client) {\n            fmt.Println(\"Connected to server\")\n        }\n        \n        func onDisconnect(client scclient.Client, err error) {\n            fmt.Printf(\"Error: %s\\n\", err.Error())\n        }\n        \n        func onConnectError(client scclient.Client, err error) {\n            fmt.Printf(\"Error: %s\\n\", err.Error())\n        }\n        \n        func onSetAuthentication(client scclient.Client, token string) {\n            fmt.Println(\"Auth token received :\", token)\n        \n        }\n        \n        func onAuthentication(client scclient.Client, isAuthenticated bool) {\n            fmt.Println(\"Client authenticated :\", isAuthenticated)\n            go startCode(client)\n        }  \n            \n        func main() {\n        \tvar reader scanner.Scanner\n        \tclient := scclient.New(\"ws://192.168.100.11:8000/socketcluster/\");\n        \tclient.SetBasicListener(onConnect, onConnectError, onDisconnect)\n        \tclient.SetAuthenticationListener(onSetAuthentication, onAuthentication)\n        \tgo client.Connect()\n        \n        \tfmt.Println(\"Enter any key to terminate the program\")\n        \treader.Init(os.Stdin)\n        \treader.Next()\n        \t// os.Exit(0)\n        }\n        \n        func startCode(client scclient.Client) {\n        \t// start writing your code from here\n        \t// All emit, receive and publish events\n        }\n        \n```\n\n#### Connecting to server\n\n- For connecting to server:\n\n```go\n    //This will send websocket handshake request to socketcluster-server\n    client.Connect()\n```\n\nEmitting and listening to events\n--------------------------------\n#### Event emitter\n\n- eventname is name of event and message can be String, boolean, int or structure\n\n```go\n\n    client.Emit(eventname,message);\n        \n    //  client.Emit(\"chat\",\"This is a sample message\")\n```\n\n- To send event with acknowledgement\n\n```go\n\n\tclient.EmitAck(\"chat\",\"This is a sample message\", func(eventName string, error interface{}, data interface{}) {\n\t\tif error == nil {\n\t\t\tfmt.Println(\"Got ack for emit event with data \", data, \" and error \", error)\n\t\t}\n\t})\n\t\n```\n\n#### Event Listener\n\n- For listening to events :\n\nThe object received can be String, Boolean, Long or GO structure.\n\n```go\n    // Receiver code without sending acknowledgement back\n    client.On(\"chat\", func(eventName string, data interface{}) {\n\t\tfmt.Println(\"Got data \", data, \" for event \", eventName)\n\t})\n    \n```\n\n- To send acknowledgement back to server\n\n```go\n    // Receiver code with ack\n\tclient.OnAck(\"chat\", func(eventName string, data interface{}, ack func(error interface{}, data interface{})) {\n\t\tfmt.Println(\"Got data \", data, \" for event \", eventName)\n\t\tfmt.Println(\"Sending back ack for the event\")\n\t\tack(\"This is error\", \"This is data\")\n\t}) \n        \n```\n\nImplementing Pub-Sub via channels\n---------------------------------\n\n#### Creating channel\n\n- For creating and subscribing to channels:\n\n```go\n    // without acknowledgement\n    client.Subscribe(\"mychannel\")\n    \n    //with acknowledgement\n    client.SubscribeAck(\"mychannel\", func(channelName string, error interface{}, data interface{}) {\n        if error == nil {\n            fmt.Println(\"Subscribed to channel \", channelName, \"successfully\")\n        }\n    })\n```\n\n\n#### Publishing event on channel\n\n- For publishing event :\n\n```go\n\n       // without acknowledgement\n       client.Publish(\"mychannel\", \"This is a data to be published\")\n\n       \n       // with acknowledgement\n       client.PublishAck(\"mychannel\", \"This is a data to be published\", func(channelName string, error interface{}, data interface{}) {\n       \t\tif error == nil {\n       \t\t\tfmt.Println(\"Data published successfully to channel \", channelName)\n       \t\t}\n       \t})\n``` \n \n#### Listening to channel\n\n- For listening to channel event :\n\n```go\n        client.OnChannel(\"mychannel\", func(channelName string, data interface{}) {\n        \t\tfmt.Println(\"Got data \", data, \" for channel \", channelName)\n        })\n    \n``` \n     \n#### Un-subscribing to channel\n\n```go\n         // without acknowledgement\n        client.Unsubscribe(\"mychannel\")\n         \n         // with acknowledgement\n        client.UnsubscribeAck(\"mychannel\", func(channelName string, error interface{}, data interface{}) {\n            if error == nil {\n                fmt.Println(\"Unsubscribed to channel \", channelName, \"successfully\")\n            }\n        })\n```\n\n#### Closing the connection with server\n```go\n    client.Disconnect()\n```\n\n#### Setting request headers\n```go\n\tclient.RequestHeader.Set(\"Accept-Encoding\",\"gzip, deflate, sdch\")\n\tclient.RequestHeader.Set(\"Accept-Language\",\"en-US,en;q=0.8\")\n\tclient.RequestHeader.Set(\"Pragma\",\"no-cache\")\n\tclient.RequestHeader.Set(\"User-Agent\",\"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36\")\n\t\n```\n\n#### Setting proxy server\n- It can be set using connectionOptions by providing url to proxy server\n\n```go\n    client.ConnectionOptions = gowebsocket.ConnectionOptions {\n       Proxy: gowebsocket.BuildProxy(\"http://example.com\"),\n    }\n```\n\n#### Setting data compression, ssl verification and subprotocols\n\n- It can be set using connectionOptions inside socket \n\n```go\n    client.ConnectionOptions = gowebsocket.ConnectionOptions {\n        UseSSL:true,\n        UseCompression:true,\n        Subprotocols: [] string{\"chat\",\"superchat\"},\n    }\n```\n\n- ConnectionOptions needs to be applied before connecting to server","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacoo7%2Fsocketcluster-client-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsacoo7%2Fsocketcluster-client-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacoo7%2Fsocketcluster-client-go/lists"}