fatedier 0f1005ff61 using glide | 7 gadi atpakaļ | |
---|---|---|
.. | ||
.gitignore | 7 gadi atpakaļ | |
.travis.yml | 7 gadi atpakaļ | |
LICENSE | 7 gadi atpakaļ | |
README.md | 7 gadi atpakaļ | |
curve.jpg | 7 gadi atpakaļ | |
frame.go | 7 gadi atpakaļ | |
mux.go | 7 gadi atpakaļ | |
mux.jpg | 7 gadi atpakaļ | |
mux_test.go | 7 gadi atpakaļ | |
session.go | 7 gadi atpakaļ | |
session_test.go | 7 gadi atpakaļ | |
smux.png | 7 gadi atpakaļ | |
stream.go | 7 gadi atpakaļ |
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.
For complete documentation, see the associated Godoc.
VERSION(1B) | CMD(1B) | LENGTH(2B) | STREAMID(4B) | DATA(LENGTH)
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)
}
Stable