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/docker/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/docker/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 © 2014-2015 Docker, Inc. All rights reserved, except as follows. Code is released under the Apache 2.0 license. The README.md file, and files in the "docs" folder are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file "LICENSE.docs". You may obtain a duplicate copy of the same license, titled CC-BY-SA-4.0, at http://creativecommons.org/licenses/by/4.0/. 78