2016-09-01 21:36:29 +08:00
2016-08-26 13:30:10 +08:00
upd
2016-08-31 17:39:34 +08:00
2016-09-01 13:24:06 +08:00
upd
2016-09-01 17:34:36 +08:00
upd
2016-08-31 23:29:36 +08:00
2016-08-26 13:30:10 +08:00
upd
2016-09-01 14:39:06 +08:00
2016-09-01 12:58:11 +08:00
2016-09-01 10:09:04 +08:00
2016-09-01 18:33:10 +08:00
2016-09-01 21:36:29 +08:00
2016-09-01 18:33:10 +08:00
2016-09-01 18:03:00 +08:00

SMUX

GoDoc MIT licensed Build Status Go Report Card Coverage Statusd

smux

Introduction

Smux (Simple MUltipleXing) is a multiplexing library for Golang. It relies on an underlying connection to provide reliability and ordering, such as TCP or KCP, and provides stream-oriented multiplexing.

Features

  1. Tiny, less than 600 LOC.
  2. Token bucket controlled receiving, which provides smoother bandwidth graph(see picture below).
  3. Session-wide receive buffer, which is shared among streams.
  4. Minimized header(8Bytes), maximized payload.

smooth bandwidth curve

Documentation

For complete documentation, see the associated Godoc.

Specification

VERSION(1B) | CMD(1B) | LENGTH(2B) | STREAMID(4B) | DATA(LENGTH)  

Usage

The API of smux are mostly taken from yamux


func client() {
    // Get a TCP connection
    conn, err := net.Dial(...)
    if err != nil {
        panic(err)
    }

    // Setup client side of smux
    session, err := smux.Client(conn, nil)
    if err != nil {
        panic(err)
    }

    // Open a new stream
    stream, err := session.OpenStream()
    if err != nil {
        panic(err)
    }

    // Stream implements net.Conn
    stream.Write([]byte("ping"))
}

func server() {
    // Accept a TCP connection
    conn, err := listener.Accept()
    if err != nil {
        panic(err)
    }

    // Setup server side of smux
    session, err := smux.Server(conn, nil)
    if err != nil {
        panic(err)
    }

    // Accept a stream
    stream, err := session.AcceptStream()
    if err != nil {
        panic(err)
    }

    // Listen for a message
    buf := make([]byte, 4)
    stream.Read(buf)
}

Status

Alpha

S
Description
A Stream Multiplexing Library for golang with least memory usage(TDMA)
Readme
669 KiB
Languages
Go 100%