{"id":16758196,"url":"https://github.com/pascaldekloe/websocket","last_synced_at":"2025-06-28T01:40:02.647Z","repository":{"id":45825716,"uuid":"163675278","full_name":"pascaldekloe/websocket","owner":"pascaldekloe","description":"WebSocket server library","archived":false,"fork":false,"pushed_at":"2023-03-26T18:14:37.000Z","size":49,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-01-24T02:20:27.460Z","etag":null,"topics":["asynchronous","rfc-6454","rfc-6455","websocket","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pascaldekloe.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}},"created_at":"2018-12-31T14:30:00.000Z","updated_at":"2024-04-23T12:35:30.737Z","dependencies_parsed_at":"2024-04-23T12:35:30.127Z","dependency_job_id":"4bf94698-dd45-4a9a-ac56-9dfc08e082bd","html_url":"https://github.com/pascaldekloe/websocket","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pascaldekloe/websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pascaldekloe%2Fwebsocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pascaldekloe%2Fwebsocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pascaldekloe%2Fwebsocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pascaldekloe%2Fwebsocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pascaldekloe","download_url":"https://codeload.github.com/pascaldekloe/websocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pascaldekloe%2Fwebsocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262361669,"owners_count":23299086,"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":["asynchronous","rfc-6454","rfc-6455","websocket","websocket-server"],"created_at":"2024-10-13T04:04:28.387Z","updated_at":"2025-06-28T01:40:02.600Z","avatar_url":"https://github.com/pascaldekloe.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## About\n\nA high-performance WebSocket library for the Go programming language\nwith built-in retry logic and timeout protection.\n\nThis is free and unencumbered software released into the\n[public domain](http://creativecommons.org/publicdomain/zero/1.0).\n\n[![API](https://pkg.go.dev/badge/github.com/pascaldekloe/websocket.svg)](https://pkg.go.dev/github.com/pascaldekloe/websocket)\n[![CI](https://github.com/pascaldekloe/websocket/actions/workflows/go.yml/badge.svg)](https://github.com/pascaldekloe/websocket/actions/workflows/go.yml)\n\n\n## Use\n\nMost implementations will boot from an\n[HTTP Upgrade](https://godoc.org/github.com/pascaldekloe/websocket/httpws#Upgrade).\n\n```go\nhttp.HandleFunc(\"/echo\", func(resp http.ResponseWriter, req *http.Request) {\n\t// client safety support\n\toriginCheck := func(s string, o *httpws.Origin) (pass bool) {\n\t\treturn o != nil \u0026\u0026 o.Host == \"example.com\" \u0026\u0026 o.Scheme == \"https\"\n\t}\n\tif !httpws.AllowOrigin(req, originCheck) {\n\t\thttp.Error(w, \"HTTP Origin rejected\", http.StatusForbidden)\n\t\treturn\n\t}\n\n\t// switch protocol to WebSocket\n\tconn, err := httpws.Upgrade(resp, req, nil, time.Second)\n\tif err != nil {\n\t\treturn\n\t}\n\tdefer conn.Close()\n\n\t// limit to standard types\n\tconn.Accept = websocket.AcceptV13\n\n\tvar buf [2048]byte\n\tfor {\n\t\t// read message\n\t\topcode, n, err := conn.Receive(buf[:], time.Second, time.Minute)\n\t\tif err != nil {\n\t\t\tif _, ok := err.(websocket.ClosedError); !ok \u0026\u0026 err != io.EOF {\n\t\t\t\tlog.Print(\"receive error: \", err)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// write message\n\t\terr = conn.Send(opcode, buf[:n], time.Second)\n\t\tif err != nil {\n\t\t\tif _, ok := err.(websocket.ClosedError); !ok {\n\t\t\t\tlog.Print(\"send error: \", err)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n})\n```\n\n\n## Performance\n\nThe `/tcp` variants wire the raw messages to display WebSocket protocol overhead.\n\n```\nname               time/op\nReceive/buffer-12   6.73µs ± 5%\nReceive/stream-12   45.7µs ± 3%\nReceive/tcp-12      6.28µs ± 3%\nSend/buffer-12      10.0µs ± 1%\nSend/stream-12      23.0µs ± 1%\nSend/tcp-12         10.0µs ± 1%\n\nname               speed\nReceive/buffer-12  888MB/s ± 5%\nReceive/stream-12  131MB/s ± 3%\nReceive/tcp-12     951MB/s ± 3%\nSend/buffer-12     598MB/s ± 1%\nSend/stream-12     260MB/s ± 1%\nSend/tcp-12        595MB/s ± 1%\n\nname               alloc/op\nReceive/buffer-12    0.00B     \nReceive/stream-12    34.0B ± 0%\nReceive/tcp-12       0.00B     \nSend/buffer-12       0.00B     \nSend/stream-12       32.0B ± 0%\nSend/tcp-12          0.00B     \n\nname               allocs/op\nReceive/buffer-12     0.00     \nReceive/stream-12     0.00     \nReceive/tcp-12        0.00     \nSend/buffer-12        0.00     \nSend/stream-12        1.00 ± 0%\nSend/tcp-12           0.00     \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpascaldekloe%2Fwebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpascaldekloe%2Fwebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpascaldekloe%2Fwebsocket/lists"}