| 136 | } |
| 137 | |
| 138 | func 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. |
| 164 | func Example_fullStackChat() { |