OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package websocket | 5 package websocket |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "http" | 9 "http" |
10 "io" | 10 "io" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 import ( | 50 import ( |
51 "websocket" | 51 "websocket" |
52 "strings" | 52 "strings" |
53 ) | 53 ) |
54 | 54 |
55 func main() { | 55 func main() { |
56 ws, err := websocket.Dial("ws://localhost/ws", "", "http://local
host/"); | 56 ws, err := websocket.Dial("ws://localhost/ws", "", "http://local
host/"); |
57 if err != nil { | 57 if err != nil { |
58 panic("Dial: ", err.String()) | 58 panic("Dial: ", err.String()) |
59 } | 59 } |
60 » » if _, err := ws.Write(strings.Bytes("hello, world!\n")); err !=
nil { | 60 » » if _, err := ws.Write([]byte("hello, world!\n")); err != nil { |
61 panic("Write: ", err.String()) | 61 panic("Write: ", err.String()) |
62 } | 62 } |
63 var msg = make([]byte, 512); | 63 var msg = make([]byte, 512); |
64 if n, err := ws.Read(msg); err != nil { | 64 if n, err := ws.Read(msg); err != nil { |
65 panic("Read: ", err.String()) | 65 panic("Read: ", err.String()) |
66 } | 66 } |
67 // use msg[0:n] | 67 // use msg[0:n] |
68 } | 68 } |
69 */ | 69 */ |
70 func Dial(url, protocol, origin string) (ws *Conn, err os.Error) { | 70 func Dial(url, protocol, origin string) (ws *Conn, err os.Error) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ws_protocol, found := resp.Header["Websocket-Protocol"] | 127 ws_protocol, found := resp.Header["Websocket-Protocol"] |
128 if !found { | 128 if !found { |
129 return ErrNoWebSocketProtocol | 129 return ErrNoWebSocketProtocol |
130 } | 130 } |
131 if ws_protocol != protocol { | 131 if ws_protocol != protocol { |
132 return ErrBadWebSocketProtocol | 132 return ErrBadWebSocketProtocol |
133 } | 133 } |
134 } | 134 } |
135 return | 135 return |
136 } | 136 } |
OLD | NEW |