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

Function ExampleDial

example_test.go:42–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42func ExampleDial() {
43 // Dials a server, writes a single JSON message and then
44 // closes the connection.
45
46 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
47 defer cancel()
48
49 c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
50 if err != nil {
51 log.Fatal(err)
52 }
53 defer c.CloseNow()
54
55 err = wsjson.Write(ctx, c, "hi")
56 if err != nil {
57 log.Fatal(err)
58 }
59
60 c.Close(websocket.StatusNormalClosure, "")
61}
62
63func ExampleCloseStatus() {
64 // Dials a server and then expects to be disconnected with status code

Callers

nothing calls this directly

Calls 4

DialFunction · 0.92
WriteFunction · 0.92
CloseNowMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…