@@ -51,6 +51,7 @@ func Example_echo() {
5151
5252 // Now we dial the server, send the messages and echo the responses.
5353 err = client ("ws://" + l .Addr ().String ())
54+ time .Sleep (time .Second )
5455 if err != nil {
5556 log .Fatalf ("client failed: %v" , err )
5657 }
@@ -66,6 +67,8 @@ func Example_echo() {
6667// It ensures the client speaks the echo subprotocol and
6768// only allows one message every 100ms with a 10 message burst.
6869func echoServer (w http.ResponseWriter , r * http.Request ) error {
70+ log .Printf ("serving %v" , r .RemoteAddr )
71+
6972 c , err := websocket .Accept (w , r , websocket.AcceptOptions {
7073 Subprotocols : []string {"echo" },
7174 })
@@ -83,15 +86,14 @@ func echoServer(w http.ResponseWriter, r *http.Request) error {
8386 for {
8487 err = echo (r .Context (), c , l )
8588 if err != nil {
86- return xerrors .Errorf ("failed to echo: %w" , err )
89+ return xerrors .Errorf ("failed to echo with %v : %w" , r . RemoteAddr , err )
8790 }
8891 }
8992}
9093
9194// echo reads from the websocket connection and then writes
9295// the received message back to it.
9396// The entire function has 10s to complete.
94- // The received message is limited to 32768 bytes.
9597func echo (ctx context.Context , c * websocket.Conn , l * rate.Limiter ) error {
9698 ctx , cancel := context .WithTimeout (ctx , time .Second * 10 )
9799 defer cancel ()
@@ -105,7 +107,6 @@ func echo(ctx context.Context, c *websocket.Conn, l *rate.Limiter) error {
105107 if err != nil {
106108 return err
107109 }
108- r = io .LimitReader (r , 32768 )
109110
110111 w , err := c .Writer (ctx , typ )
111112 if err != nil {
0 commit comments