Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: close listener, connection and stream in echo client and server #4188

Merged
merged 3 commits into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions example/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Loading