{"id":15632915,"url":"https://github.com/sacoo7/gowebsocket","last_synced_at":"2025-04-04T09:08:39.536Z","repository":{"id":29101349,"uuid":"117645668","full_name":"sacOO7/GoWebsocket","owner":"sacOO7","description":"Gorilla websockets based simplified websocket-client implementation in GO.","archived":false,"fork":false,"pushed_at":"2022-11-09T08:11:33.000Z","size":27,"stargazers_count":171,"open_issues_count":12,"forks_count":64,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T08:06:48.645Z","etag":null,"topics":["client","concurrency-control","event-driven","go","golang","gorilla","listener-pattern","websocket"],"latest_commit_sha":null,"homepage":"","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}},"created_at":"2018-01-16T07:05:55.000Z","updated_at":"2025-03-21T08:52:27.000Z","dependencies_parsed_at":"2022-08-07T14:15:11.653Z","dependency_job_id":null,"html_url":"https://github.com/sacOO7/GoWebsocket","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%2FGoWebsocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2FGoWebsocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2FGoWebsocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacOO7%2FGoWebsocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sacOO7","download_url":"https://codeload.github.com/sacOO7/GoWebsocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"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","concurrency-control","event-driven","go","golang","gorilla","listener-pattern","websocket"],"created_at":"2024-10-03T10:45:48.707Z","updated_at":"2025-04-04T09:08:39.515Z","avatar_url":"https://github.com/sacOO7.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoWebsocket\nGorilla websocket based simplified client implementation in GO.\n\nOverview\n--------\nThis client provides following easy to implement functionality\n- Support for emitting and receiving text and binary data\n- Data compression\n- Concurrency control\n- Proxy support\n- Setting request headers\n- Subprotocols support\n- SSL verification enable/disable\n\nTo install use\n\n```markdown\n    go get github.com/sacOO7/gowebsocket\n```\n\nDescription\n-----------\n\nCreate instance of `Websocket` by passing url of websocket-server end-point\n\n```go\n    //Create a client instance\n    socket := gowebsocket.New(\"ws://echo.websocket.org/\")\n    \n```\n \n**Important Note** : url to websocket server must be specified with either **ws** or **wss**.\n\n#### Connecting to server\n- For connecting to server:\n\n```go\n    //This will send websocket handshake request to socketcluster-server\n    socket.Connect()\n```\n\n#### Registering All Listeners\n```go\n    package main\n    \n    import (\n    \t\"log\"\n    \t\"github.com/sacOO7/gowebsocket\"\n        \"os\"\n        \"os/signal\"\n    )\n    \n    func main() {\n    \n        interrupt := make(chan os.Signal, 1)\n        signal.Notify(interrupt, os.Interrupt)\n        \n    \tsocket := gowebsocket.New(\"ws://echo.websocket.org/\");\n    \t\n    \tsocket.OnConnected = func(socket gowebsocket.Socket) {\n    \t\tlog.Println(\"Connected to server\");\n    \t};\n    \t\n        socket.OnConnectError = func(err error, socket gowebsocket.Socket) {\n            log.Println(\"Received connect error \", err)\n        };\n        \n    \tsocket.OnTextMessage = func(message string, socket gowebsocket.Socket) {\n    \t\tlog.Println(\"Received message \" + message)\n    \t};\n    \t\n    \tsocket.OnBinaryMessage = func(data [] byte, socket gowebsocket.Socket) {\n            log.Println(\"Received binary data \", data)\n        };\n        \n    \tsocket.OnPingReceived = func(data string, socket gowebsocket.Socket) {\n    \t\tlog.Println(\"Received ping \" + data)\n    \t};\n    \t\n    \tsocket.OnPongReceived = func(data string, socket gowebsocket.Socket) {\n            log.Println(\"Received pong \" + data)\n        };\n        \n    \tsocket.OnDisconnected = func(err error, socket gowebsocket.Socket) {\n    \t\tlog.Println(\"Disconnected from server \")\n    \t\treturn\n    \t};\n    \t\n    \tsocket.Connect()\n    \t\n        for {\n            select {\n            case \u003c-interrupt:\n                log.Println(\"interrupt\")\n                socket.Close()\n                return\n            }\n        }\n    }\n    \n``` \n\n#### Sending Text message\n\n```go\n    socket.SendText(\"Hi there, this is my sample test message\")\n```\n\n#### Sending Binary data\n```go\n    token := make([]byte, 4)\n    // rand.Read(token) putting some random value in token\n    socket.SendBinary(token)\n```\n\n#### Closing the connection with server\n```go\n    socket.Close()\n```\n\n#### Setting request headers\n```go\n\tsocket.RequestHeader.Set(\"Accept-Encoding\",\"gzip, deflate, sdch\")\n\tsocket.RequestHeader.Set(\"Accept-Language\",\"en-US,en;q=0.8\")\n\tsocket.RequestHeader.Set(\"Pragma\",\"no-cache\")\n\tsocket.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    socket.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    socket.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\n- Please checkout [**examples/gowebsocket**](!https://github.com/sacOO7/GoWebsocket/tree/master/examples/gowebsocket) directory for detailed code..\n\nLicense\n-------\nApache License, Version 2.0\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacoo7%2Fgowebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsacoo7%2Fgowebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacoo7%2Fgowebsocket/lists"}