Slide 26
Slide 26 text
Smux (Socket Multiplexer)
26
// smux server
server := smux.Server{
Network: "tcp", // or "unix"
Address: "localhost:3000", // or "sockfile"
Handler: smux.HandlerFunc(func(w io.Writer, r io.Reader) {
io.Copy(ioutil.Discard, r)
fmt.Fprint(w, "Hello, smux client!")
}),
}
server.ListenAndServe()
// smux client
client := smux.Client{
Network: "tcp", // or "unix"
Address: "localhost:3000", // or "sockfile"
}
body, _ := client.Post([]byte("Hello, smux server!"))
fmt.Printf("%s\n", body) // "Hello, smux client!"
Server
Client