{"id":22332722,"url":"https://github.com/xgfone/go-websocket","last_synced_at":"2025-07-29T19:33:28.730Z","repository":{"id":57485000,"uuid":"156215578","full_name":"xgfone/go-websocket","owner":"xgfone","description":"Another websocket implementation, which is inspired by https://github.com/noVNC/websockify and https://github.com/gorilla/websocket.","archived":false,"fork":false,"pushed_at":"2023-10-19T12:50:36.000Z","size":87,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T20:49:14.603Z","etag":null,"topics":["go","go-websocket","golang","novnc","proxy","vnc","vnc-proxy","websocket","websocket-client","websocket-library","websocket-server","websocket-vnc","ws"],"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/xgfone.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-11-05T12:37:06.000Z","updated_at":"2023-12-18T09:11:19.000Z","dependencies_parsed_at":"2022-08-26T11:10:58.699Z","dependency_job_id":"f9e5d1c9-cbe4-4c0c-83da-7f0fbc7f0e51","html_url":"https://github.com/xgfone/go-websocket","commit_stats":null,"previous_names":["xgfone/websocket"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/go-websocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228042008,"owners_count":17860354,"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":["go","go-websocket","golang","novnc","proxy","vnc","vnc-proxy","websocket","websocket-client","websocket-library","websocket-server","websocket-vnc","ws"],"created_at":"2024-12-04T04:19:28.843Z","updated_at":"2024-12-04T04:19:29.460Z","avatar_url":"https://github.com/xgfone.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# websocket [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-websocket)](https://pkg.go.dev/github.com/xgfone/go-websocket) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-websocket/master/LICENSE)\n\nThis is a websocket implementation supporting `Go1.7+`, which is inspired by [websockify](https://github.com/novnc/websockify) and [websocket](https://github.com/gorilla/websocket).\n\n#### Difference from `gorilla/websocket`\n- `gorilla/websocket` only has a goroutine to read from websocket and a goroutine to write to websocket, that's, read or write can be done concurrently.\n- Though this library cannot read from websocket concurrently, it's able to write to websocket concurrently. Moreover, it will be enhanced to read concurrently.\n\n## Install\n\n```shell\n$ go get -u github.com/xgfone/go-websocket\n```\n\n## VNC Proxy on WebSocket\n\nThe sub-package [vncproxy](https://github.com/xgfone/go-websocket/tree/master/vncproxy) provides a HTTP handler about VNC Proxy on Websocket.\n\n## Example\n\n### Websocket Server Example\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/xgfone/go-websocket\"\n)\n\nvar upgrader = websocket.Upgrader{\n\tMaxMsgSize:  1024,\n\tTimeout:     time.Second * 30,\n\tCheckOrigin: func(r *http.Request) bool { return true },\n}\n\nfunc websocketHandler(rw http.ResponseWriter, r *http.Request) {\n\tws, err := upgrader.Upgrade(rw, r, nil)\n\tif err != nil {\n\t\tlog.Printf(\"failed to upgrade to websocket: %s\\n\", err)\n\t\treturn\n\t}\n\n\tws.Run(func(msgType int, message []byte) {\n\t\tswitch msgType {\n\t\tcase websocket.MsgTypeBinary:\n\t\t\tws.SendBinaryMsg(message)\n\t\tcase websocket.MsgTypeText:\n\t\t\tws.SendTextMsg(message)\n\t\t}\n\t})\n}\n\nfunc main() {\n\thttp.ListenAndServe(\":80\", http.HandlerFunc(websocketHandler))\n}\n```\n\n### Websocket Client Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/xgfone/go-websocket\"\n)\n\nfunc main() {\n\tws, err := websocket.NewClientWebsocket(\"ws://127.0.0.1/\")\n\tif err == nil {\n\t\tgo func() {\n\t\t\ttick := time.NewTicker(time.Second * 10)\n\t\t\tdefer tick.Stop()\n\t\t\tfor {\n\t\t\t\tselect {\n\t\t\t\tcase now := \u003c-tick.C:\n\t\t\t\t\tif err := ws.SendTextMsg([]byte(now.String())); err != nil {\n\t\t\t\t\t\tfmt.Println(err)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}()\n\n\t\terr = ws.Run(func(msgType int, msg []byte) {\n\t\t\tfmt.Printf(\"Receive: %s\\n\", string(msg))\n\t\t})\n\t}\n\tfmt.Println(err)\n}\n```\n\nThe client will output like this:\n```\nReceive: 2019-07-13 18:33:47.951688 +0800 CST m=+10.007139340\nReceive: 2019-07-13 18:33:57.951479 +0800 CST m=+20.006605995\nReceive: 2019-07-13 18:34:07.948628 +0800 CST m=+30.003442484\nReceive: 2019-07-13 18:34:17.949763 +0800 CST m=+40.004270178\nReceive: 2019-07-13 18:34:27.947877 +0800 CST m=+50.002081112\nReceive: 2019-07-13 18:34:37.949986 +0800 CST m=+60.003888082\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fgo-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-websocket/lists"}