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

Function ExampleConn_Ping

example_test.go:138–161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136}
137
138func ExampleConn_Ping() {
139 // Dials a server and pings it 5 times.
140
141 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
142 defer cancel()
143
144 c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
145 if err != nil {
146 log.Fatal(err)
147 }
148 defer c.CloseNow()
149
150 // Required to read the Pongs from the server.
151 ctx = c.CloseRead(ctx)
152
153 for range 5 {
154 err = c.Ping(ctx)
155 if err != nil {
156 log.Fatal(err)
157 }
158 }
159
160 c.Close(websocket.StatusNormalClosure, "")
161}
162
163// This example demonstrates full stack chat with an automated test.
164func Example_fullStackChat() {

Callers

nothing calls this directly

Calls 5

DialFunction · 0.92
CloseNowMethod · 0.45
CloseReadMethod · 0.45
PingMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…