OLD | NEW |
1 package jsoncodec | 1 package jsoncodec |
2 | 2 |
3 import ( | 3 import ( |
4 "code.google.com/p/go.net/websocket" | |
5 "encoding/json" | 4 "encoding/json" |
6 "net" | 5 "net" |
| 6 |
| 7 "code.google.com/p/go.net/websocket" |
7 ) | 8 ) |
8 | 9 |
9 // NewWebsocket returns an rpc codec that uses the given websocket | 10 // NewWebsocket returns an rpc codec that uses the given websocket |
10 // connection to send and receive messages. | 11 // connection to send and receive messages. |
11 func NewWebsocket(conn *websocket.Conn) *Codec { | 12 func NewWebsocket(conn *websocket.Conn) *Codec { |
12 return New(wsJSONConn{conn}) | 13 return New(wsJSONConn{conn}) |
13 } | 14 } |
14 | 15 |
15 type wsJSONConn struct { | 16 type wsJSONConn struct { |
16 conn *websocket.Conn | 17 conn *websocket.Conn |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return conn.enc.Encode(msg) | 49 return conn.enc.Encode(msg) |
49 } | 50 } |
50 | 51 |
51 func (conn *netConn) Receive(msg interface{}) error { | 52 func (conn *netConn) Receive(msg interface{}) error { |
52 return conn.dec.Decode(msg) | 53 return conn.dec.Decode(msg) |
53 } | 54 } |
54 | 55 |
55 func (conn *netConn) Close() error { | 56 func (conn *netConn) Close() error { |
56 return conn.conn.Close() | 57 return conn.conn.Close() |
57 } | 58 } |
OLD | NEW |