A multiplexed stream library using spdy
Client example (connecting to mirroring server without auth)
package main
import (
"fmt""github.com/moby/spdystream""net""net/http"
)
funcmain() {
conn, err:=net.Dial("tcp", "localhost:8080")
iferr!=nil {
panic(err)
}
spdyConn, err:=spdystream.NewConnection(conn, false)
iferr!=nil {
panic(err)
}
gospdyConn.Serve(spdystream.NoOpStreamHandler)
stream, err:=spdyConn.CreateStream(http.Header{}, nil, false)
iferr!=nil {
panic(err)
}
stream.Wait()
fmt.Fprint(stream, "Writing to stream")
buf:=make([]byte, 25)
stream.Read(buf)
fmt.Println(string(buf))
stream.Close()
}Server example (mirroring server without auth)
package main
import (
"github.com/moby/spdystream""net"
)
funcmain() {
listener, err:=net.Listen("tcp", "localhost:8080")
iferr!=nil {
panic(err)
}
for {
conn, err:=listener.Accept()
iferr!=nil {
panic(err)
}
spdyConn, err:=spdystream.NewConnection(conn, true)
iferr!=nil {
panic(err)
}
gospdyConn.Serve(spdystream.MirrorStreamHandler)
}
}Copyright 2013-2021 Docker, inc. Released under the Apache 2.0 license.