forked from quic-go/quic-go
examples: close listener, connection and stream in echo client and server (#4188)
* fix: add close func in example Signed-off-by: rfyiamcool <rfyiamcool@163.com> * fix: add close func in example Signed-off-by: rfyiamcool <rfyiamcool@163.com> * fix: add close func in example Signed-off-by: rfyiamcool <rfyiamcool@163.com> --------- Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
@@ -36,14 +36,19 @@ func echoServer() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := listener.Accept(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stream, err := conn.AcceptStream(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
// Echo through the loggingWriter
|
||||
_, err = io.Copy(loggingWriter{stream}, stream)
|
||||
return err
|
||||
@@ -58,11 +63,13 @@ func clientMain() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.CloseWithError(0, "")
|
||||
|
||||
stream, err := conn.OpenStreamSync(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
fmt.Printf("Client: Sending '%s'\n", message)
|
||||
_, err = stream.Write([]byte(message))
|
||||
|
||||
Reference in New Issue
Block a user