...
1# SpdyStream
2
3A multiplexed stream library using spdy
4
5## Usage
6
7Client example (connecting to mirroring server without auth)
8
9```go
10package main
11
12import (
13 "fmt"
14 "github.com/moby/spdystream"
15 "net"
16 "net/http"
17)
18
19func main() {
20 conn, err := net.Dial("tcp", "localhost:8080")
21 if err != nil {
22 panic(err)
23 }
24 spdyConn, err := spdystream.NewConnection(conn, false)
25 if err != nil {
26 panic(err)
27 }
28 go spdyConn.Serve(spdystream.NoOpStreamHandler)
29 stream, err := spdyConn.CreateStream(http.Header{}, nil, false)
30 if err != nil {
31 panic(err)
32 }
33
34 stream.Wait()
35
36 fmt.Fprint(stream, "Writing to stream")
37
38 buf := make([]byte, 25)
39 stream.Read(buf)
40 fmt.Println(string(buf))
41
42 stream.Close()
43}
44```
45
46Server example (mirroring server without auth)
47
48```go
49package main
50
51import (
52 "github.com/moby/spdystream"
53 "net"
54)
55
56func main() {
57 listener, err := net.Listen("tcp", "localhost:8080")
58 if err != nil {
59 panic(err)
60 }
61 for {
62 conn, err := listener.Accept()
63 if err != nil {
64 panic(err)
65 }
66 spdyConn, err := spdystream.NewConnection(conn, true)
67 if err != nil {
68 panic(err)
69 }
70 go spdyConn.Serve(spdystream.MirrorStreamHandler)
71 }
72}
73```
74
75## Copyright and license
76
77Copyright 2013-2021 Docker, inc. Released under the [Apache 2.0 license](LICENSE).
View as plain text