...
1
2
3
4
5 package websocket_test
6
7 import (
8 "fmt"
9 "log"
10
11 "golang.org/x/net/websocket"
12 )
13
14
15 func ExampleDial() {
16 origin := "http://localhost/"
17 url := "ws://localhost:12345/ws"
18 ws, err := websocket.Dial(url, "", origin)
19 if err != nil {
20 log.Fatal(err)
21 }
22 if _, err := ws.Write([]byte("hello, world!\n")); err != nil {
23 log.Fatal(err)
24 }
25 var msg = make([]byte, 512)
26 var n int
27 if n, err = ws.Read(msg); err != nil {
28 log.Fatal(err)
29 }
30 fmt.Printf("Received: %s.\n", msg[:n])
31 }
32
View as plain text