{"id":13630431,"url":"https://github.com/xtaci/smux","last_synced_at":"2025-05-12T15:16:13.412Z","repository":{"id":41063260,"uuid":"66619304","full_name":"xtaci/smux","owner":"xtaci","description":"A Stream Multiplexing Library for golang with least memory usage(TDMA)","archived":false,"fork":false,"pushed_at":"2025-02-17T14:12:39.000Z","size":504,"stargazers_count":1367,"open_issues_count":27,"forks_count":199,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-04-21T19:44:01.314Z","etag":null,"topics":["stream-multiplexing"],"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/xtaci.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":"2016-08-26T05:30:10.000Z","updated_at":"2025-04-21T07:21:38.000Z","dependencies_parsed_at":"2024-09-08T14:14:28.775Z","dependency_job_id":"68876b88-a176-4838-8bac-36cac22b49a2","html_url":"https://github.com/xtaci/smux","commit_stats":{"total_commits":352,"total_committers":20,"mean_commits":17.6,"dds":"0.12215909090909094","last_synced_commit":"56edb247033f56f345ffd699dfb41ce9d2f9b472"},"previous_names":[],"tags_count":74,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fsmux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fsmux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fsmux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fsmux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtaci","download_url":"https://codeload.github.com/xtaci/smux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250324687,"owners_count":21411943,"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":["stream-multiplexing"],"created_at":"2024-08-01T22:01:42.341Z","updated_at":"2025-04-23T17:11:25.503Z","avatar_url":"https://github.com/xtaci.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003cimg src=\"assets/smux.png\" alt=\"smux\" height=\"35px\" /\u003e\n\n[![GoDoc][1]][2] [![MIT licensed][3]][4] [![Build Status][5]][6] [![Go Report Card][7]][8] [![Coverage Statusd][9]][10] [![Sourcegraph][11]][12]\n\n\u003cimg src=\"assets/mux.jpg\" alt=\"smux\" height=\"120px\" /\u003e \n\n[1]: https://godoc.org/github.com/xtaci/smux?status.svg\n[2]: https://godoc.org/github.com/xtaci/smux\n[3]: https://img.shields.io/badge/license-MIT-blue.svg\n[4]: LICENSE\n[5]: https://img.shields.io/github/created-at/xtaci/smux\n[6]: https://img.shields.io/github/created-at/xtaci/smux\n[7]: https://goreportcard.com/badge/github.com/xtaci/smux\n[8]: https://goreportcard.com/report/github.com/xtaci/smux\n[9]: https://codecov.io/gh/xtaci/smux/branch/master/graph/badge.svg\n[10]: https://codecov.io/gh/xtaci/smux\n[11]: https://sourcegraph.com/github.com/xtaci/smux/-/badge.svg\n[12]: https://sourcegraph.com/github.com/xtaci/smux?badge\n\n## Introduction\n\nSmux ( **S**imple **MU**ltiple**X**ing) is a multiplexing library for Golang. It relies on an underlying connection to provide reliability and ordering, such as TCP or [KCP](https://github.com/xtaci/kcp-go), and provides stream-oriented multiplexing. The original intention of this library is to power the connection management for [kcp-go](https://github.com/xtaci/kcp-go).\n\n## Features\n\n1. ***Token bucket*** controlled receiving, which provides smoother bandwidth graph(see picture below).\n2. Session-wide receive buffer, shared among streams, **fully controlled** overall memory usage.\n3. Minimized header(8Bytes), maximized payload. \n4. Well-tested on millions of devices in [kcptun](https://github.com/xtaci/kcptun).\n5. Builtin fair queue traffic shaping.\n6. Per-stream sliding window to control congestion.(protocol version 2+).\n\n![smooth bandwidth curve](assets/curve.jpg)\n\n## Documentation\n\nFor complete documentation, see the associated [Godoc](https://godoc.org/github.com/xtaci/smux).\n\n## Benchmark\n```\n$ go test -v -run=^$ -bench .\ngoos: darwin\ngoarch: amd64\npkg: github.com/xtaci/smux\nBenchmarkMSB-4           \t30000000\t        51.8 ns/op\nBenchmarkAcceptClose-4   \t   50000\t     36783 ns/op\nBenchmarkConnSmux-4      \t   30000\t     58335 ns/op\t2246.88 MB/s\t    1208 B/op\t      19 allocs/op\nBenchmarkConnTCP-4       \t   50000\t     25579 ns/op\t5124.04 MB/s\t       0 B/op\t       0 allocs/op\nPASS\nok  \tgithub.com/xtaci/smux\t7.811s\n```\n\n## Specification\n\n```\nVERSION(1B) | CMD(1B) | LENGTH(2B) | STREAMID(4B) | DATA(LENGTH)  \n\nVALUES FOR LATEST VERSION:\nVERSION:\n    1/2\n    \nCMD:\n    cmdSYN(0)\n    cmdFIN(1)\n    cmdPSH(2)\n    cmdNOP(3)\n    cmdUPD(4)\t// only supported on version 2\n    \nSTREAMID:\n    client use odd numbers starts from 1\n    server use even numbers starts from 0\n    \ncmdUPD:\n    | CONSUMED(4B) | WINDOW(4B) |\n```\n\n## Usage\n\n```go\n\nfunc client() {\n    // Get a TCP connection\n    conn, err := net.Dial(...)\n    if err != nil {\n        panic(err)\n    }\n\n    // Setup client side of smux\n    session, err := smux.Client(conn, nil)\n    if err != nil {\n        panic(err)\n    }\n\n    // Open a new stream\n    stream, err := session.OpenStream()\n    if err != nil {\n        panic(err)\n    }\n\n    // Stream implements io.ReadWriteCloser\n    stream.Write([]byte(\"ping\"))\n    stream.Close()\n    session.Close()\n}\n\nfunc server() {\n    // Accept a TCP connection\n    conn, err := listener.Accept()\n    if err != nil {\n        panic(err)\n    }\n\n    // Setup server side of smux\n    session, err := smux.Server(conn, nil)\n    if err != nil {\n        panic(err)\n    }\n\n    // Accept a stream\n    stream, err := session.AcceptStream()\n    if err != nil {\n        panic(err)\n    }\n\n    // Listen for a message\n    buf := make([]byte, 4)\n    stream.Read(buf)\n    stream.Close()\n    session.Close()\n}\n\n```\n\n## Status\n\nStable\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtaci%2Fsmux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtaci%2Fsmux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtaci%2Fsmux/lists"}