MCPcopy
hub / github.com/coder/websocket / echo

Function echo

internal/examples/echo/server.go:54–80  ·  view source on GitHub ↗

echo reads from the WebSocket connection and then writes the received message back to it. The entire function has 10s to complete.

(c *websocket.Conn, l *rate.Limiter)

Source from the content-addressed store, hash-verified

52// the received message back to it.
53// The entire function has 10s to complete.
54func echo(c *websocket.Conn, l *rate.Limiter) error {
55 ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
56 defer cancel()
57
58 err := l.Wait(ctx)
59 if err != nil {
60 return err
61 }
62
63 typ, r, err := c.Reader(ctx)
64 if err != nil {
65 return err
66 }
67
68 w, err := c.Writer(ctx, typ)
69 if err != nil {
70 return err
71 }
72
73 _, err = io.Copy(w, r)
74 if err != nil {
75 return fmt.Errorf("failed to io.Copy: %w", err)
76 }
77
78 err = w.Close()
79 return err
80}

Callers 1

ServeHTTPMethod · 0.85

Calls 3

ReaderMethod · 0.45
WriterMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…