aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/golang.org/x/net/websocket/exampledial_test.go
blob: 72bb9d48ebadd2188cfd19f6e42e36e3e8488b56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package websocket_test

import (
    "fmt"
    "log"

    "golang.org/x/net/websocket"
)

// This example demonstrates a trivial client.
func ExampleDial() {
    origin := "http://localhost/"
    url := "ws://localhost:12345/ws"
    ws, err := websocket.Dial(url, "", origin)
    if err != nil {
        log.Fatal(err)
    }
    if _, err := ws.Write([]byte("hello, world!\n")); err != nil {
        log.Fatal(err)
    }
    var msg = make([]byte, 512)
    var n int
    if n, err = ws.Read(msg); err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Received: %s.\n", msg[:n])
}