mirror of https://github.com/fatedier/frp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fatedier
93d86ca635
|
8 years ago | |
---|---|---|
.. | ||
.gitignore | 8 years ago | |
.travis.yml | 8 years ago | |
LICENSE | 8 years ago | |
README.md | 8 years ago | |
curve.jpg | 8 years ago | |
frame.go | 8 years ago | |
mux.go | 8 years ago | |
mux.jpg | 8 years ago | |
session.go | 8 years ago | |
smux.png | 8 years ago | |
stream.go | 8 years ago |
README.md
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. The original intention of this library is to power the connection management for kcp-go.
Features
- Tiny, less than 600 LOC.
- Token bucket controlled receiving, which provides smoother bandwidth graph(see picture below).
- Session-wide receive buffer, shared among streams, tightly controlled overall memory usage.
- Minimized header(8Bytes), maximized payload.
- Well-tested on millions of devices in kcptun.
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 io.ReadWriteCloser
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
Stable