~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/golang.org/x/net/websocket/exampledial_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012 The Go Authors. All rights reserved.
 
2
// Use of this source code is governed by a BSD-style
 
3
// license that can be found in the LICENSE file.
 
4
 
 
5
package websocket_test
 
6
 
 
7
import (
 
8
        "fmt"
 
9
        "log"
 
10
 
 
11
        "golang.org/x/net/websocket"
 
12
)
 
13
 
 
14
// This example demonstrates a trivial client.
 
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
}