{"id":15903859,"url":"https://github.com/onionj/websocket-mux","last_synced_at":"2025-07-26T09:14:15.783Z","repository":{"id":222724270,"uuid":"758207077","full_name":"onionj/websocket-mux","owner":"onionj","description":"Muxr: Efficient WebSocket Multiplexing Library for Go","archived":false,"fork":false,"pushed_at":"2025-03-13T18:44:05.000Z","size":43,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T07:41:22.636Z","etag":null,"topics":["multiplexer","mux","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","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/onionj.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":"2024-02-15T20:44:15.000Z","updated_at":"2025-03-13T18:44:02.000Z","dependencies_parsed_at":"2024-04-15T22:33:06.130Z","dependency_job_id":"95d775de-8239-4860-9668-3f2fb3394886","html_url":"https://github.com/onionj/websocket-mux","commit_stats":null,"previous_names":["onionj/websocket-mux"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/onionj/websocket-mux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onionj%2Fwebsocket-mux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onionj%2Fwebsocket-mux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onionj%2Fwebsocket-mux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onionj%2Fwebsocket-mux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onionj","download_url":"https://codeload.github.com/onionj/websocket-mux/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onionj%2Fwebsocket-mux/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267144574,"owners_count":24042637,"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-07-26T02:00:08.937Z","response_time":62,"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":["multiplexer","mux","websocket"],"created_at":"2024-10-06T12:04:38.436Z","updated_at":"2025-07-26T09:14:15.762Z","avatar_url":"https://github.com/onionj.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Muxr: Efficient WebSocket Multiplexing for Go\n\nMuxr is a Go package designed to simplify WebSocket communication by offering efficient multiplexing capabilities. It enables you to manage multiple streams over a single WebSocket connection, where each stream can handle multiple requests and responses, effectively streamlining communication between clients and servers.\n\n\u003e **Note**: If user connect to a muxr server with a regular WebSocket client, the muxr server handles it in single stream mode.\n\n## Features\n\n- **Stream Multiplexing**: Handle multiple streams concurrently over a single WebSocket connection.\n- **Flexible Communication**: Each stream can manage multiple requests and responses independently.\n- **Simplified Integration**: Seamlessly integrate into existing Go applications for WebSocket communication.\n\n## Installation\n\nInstall Muxr using `go get`:\n\n```bash\ngo get github.com/onionj/websocket-mux/muxr\n```\n\n## Usage\n\n### Muxr Server\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/onionj/websocket-mux/muxr\"\n)\n\nfunc main() {    \n    // Create a new Muxr server listening on port 8080.\n    server := muxr.NewWsServer(\":8080\")\n\n    // Handle WebSocket connections on the \"/api\" endpoint.\n    server.Handle(\"/api\", func(stream *muxr.Stream) {\n        for {\n            // Read data from the client.\n            data, err := stream.Read()\n            if err != nil {\n                fmt.Println(\"Error reading from client:\", err)\n                return\n            }\n            fmt.Println(\"Server received:\", string(data))\n\n            // Send a response back to the client.\n            msg := []byte(\"Pong\")\n            err = stream.Write(msg)\n            if err != nil {\n                fmt.Println(\"Error writing to client:\", err)\n                return\n            }\n            fmt.Println(\"Server sent:\", string(msg))\n        }\n    })\n\n    // Start the Muxr server.\n    err := server.ListenAndServe()\n    if err != nil {\n        fmt.Println(\"Error starting server:\", err)\n        return\n    }\n}\n```\n\n\u003e **Note**: For handling TLS, use: `server.ListenAndServeTLS(certFile, keyFile)`\n\n### Muxr Client\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/onionj/websocket-mux/muxr\"\n)\n\nfunc main() {\n    // Create a new Muxr client connecting to the server.\n    client := muxr.NewClient(\"ws://127.0.0.1:8080/api\")\n    closerFunc, err := client.StartForever()\n    if err != nil {\n        panic(err)\n    }\n    defer closerFunc()\n\n    // Establish a stream for communication with the server.\n    stream, err := client.Dial()\n    if err != nil {\n        fmt.Println(\"Error establishing stream:\", err)\n        return\n    }\n    defer stream.Close()\n\n    // Send a message to the server.\n    msg := []byte(\"Ping\")\n    if err = stream.Write(msg); err != nil {\n        fmt.Println(\"Error sending message:\", err)\n        return\n    }\n    fmt.Println(\"Client sent:\", string(msg))\n\n    // Read the response from the server.\n    data, err := stream.Read()\n    if err != nil {\n        fmt.Println(\"Error reading response:\", err)\n        return\n    }\n    fmt.Println(\"Client received:\", string(data))\n}\n\n```\n\n## Examples\nExplore additional examples provided in the [example](./example/) directory\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonionj%2Fwebsocket-mux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonionj%2Fwebsocket-mux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonionj%2Fwebsocket-mux/lists"}