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

Method Ping

conn.go:223–231  ·  view source on GitHub ↗

Ping sends a ping to the peer and waits for a pong. Use this to measure latency or ensure the peer is responsive. Ping must be called concurrently with Reader as it does not read from the connection but instead waits for a Reader call to read the pong. TCP Keepalives should suffice for most use cas

(ctx context.Context)

Source from the content-addressed store, hash-verified

221//
222// TCP Keepalives should suffice for most use cases.
223func (c *Conn) Ping(ctx context.Context) error {
224 p := c.pingCounter.Add(1)
225
226 err := c.ping(ctx, strconv.FormatInt(p, 10))
227 if err != nil {
228 return fmt.Errorf("failed to ping: %w", err)
229 }
230 return nil
231}
232
233func (c *Conn) ping(ctx context.Context, p string) error {
234 pong := make(chan struct{}, 1)

Callers 3

TestConnFunction · 0.45
TestConcurrentClosePingFunction · 0.45
ExampleConn_PingFunction · 0.45

Calls 1

pingMethod · 0.95

Tested by 3

TestConnFunction · 0.36
TestConcurrentClosePingFunction · 0.36
ExampleConn_PingFunction · 0.36