@@ -51,6 +51,7 @@ func Example_echo() {
51
51
52
52
// Now we dial the server, send the messages and echo the responses.
53
53
err = client ("ws://" + l .Addr ().String ())
54
+ time .Sleep (time .Second )
54
55
if err != nil {
55
56
log .Fatalf ("client failed: %v" , err )
56
57
}
@@ -66,6 +67,8 @@ func Example_echo() {
66
67
// It ensures the client speaks the echo subprotocol and
67
68
// only allows one message every 100ms with a 10 message burst.
68
69
func echoServer (w http.ResponseWriter , r * http.Request ) error {
70
+ log .Printf ("serving %v" , r .RemoteAddr )
71
+
69
72
c , err := websocket .Accept (w , r , websocket.AcceptOptions {
70
73
Subprotocols : []string {"echo" },
71
74
})
@@ -83,15 +86,14 @@ func echoServer(w http.ResponseWriter, r *http.Request) error {
83
86
for {
84
87
err = echo (r .Context (), c , l )
85
88
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 )
87
90
}
88
91
}
89
92
}
90
93
91
94
// echo reads from the websocket connection and then writes
92
95
// the received message back to it.
93
96
// The entire function has 10s to complete.
94
- // The received message is limited to 32768 bytes.
95
97
func echo (ctx context.Context , c * websocket.Conn , l * rate.Limiter ) error {
96
98
ctx , cancel := context .WithTimeout (ctx , time .Second * 10 )
97
99
defer cancel ()
@@ -105,7 +107,6 @@ func echo(ctx context.Context, c *websocket.Conn, l *rate.Limiter) error {
105
107
if err != nil {
106
108
return err
107
109
}
108
- r = io .LimitReader (r , 32768 )
109
110
110
111
w , err := c .Writer (ctx , typ )
111
112
if err != nil {
0 commit comments