Rev 1651 | Rev 1962 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1651 | Rev 1959 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | Socket_Connections = {}; |
2 | var Socket_Connections = {}; |
| - | 3 | ||
| - | 4 | var SOCKET_STATE_CONNECTED = 0x00; |
|
| - | 5 | var SOCKET_STATE_DISCONNECTED = 0x01; |
|
| - | 6 | var SOCKET_STATE_ACCEPTED = 0x02; |
|
| 3 | 7 | ||
| 4 | function Socket_OnNewData(socket_id, data) |
8 | function Socket_OnNewData(socket_id, data) |
| 5 | { |
9 | { |
| 6 | if (Socket_Connections[socket_id]) |
10 | if (Socket_Connections[socket_id]) |
| 7 | { |
11 | { |
| 8 | Socket_Connections[socket_id]["ondata"](socket_id, data); |
12 | Socket_Connections[socket_id]["ondata"](socket_id, data); |
| 9 | } |
13 | } |
| 10 | } |
14 | } |
| 11 | 15 | ||
| 12 | function Socket_OnNewState(socket_id, state) |
16 | function Socket_OnNewState(socket_id, state) |
| 13 | { |
17 | { |
| 14 | if (Socket_Connections[socket_id]) |
18 | if (Socket_Connections[socket_id]) |
| 15 | { |
19 | { |
| 16 | Socket_Connections[socket_id]["onstate"](socket_id, state); |
20 | Socket_Connections[socket_id]["onstate"](socket_id, state); |
| 17 | } |
21 | } |
| - | 22 | } |
|
| - | 23 | ||
| - | 24 | function Socket_StartServer(port, ondata_callback, onstate_callback) |
|
| - | 25 | { |
|
| - | 26 | socket_id = SocketExport_StartServer(port); |
|
| - | 27 | ||
| - | 28 | if (socket_id > 0) |
|
| - | 29 | { |
|
| - | 30 | Socket_Connections[socket_id] = { "ondata" : ondata_callback, "onstate" : onstate_callback }; |
|
| - | 31 | } |
|
| - | 32 | ||
| - | 33 | return socket_id; |
|
| 18 | } |
34 | } |
| 19 | 35 | ||
| 20 | function Socket_Connect(address, port, ondata_callback, onstate_callback) |
36 | function Socket_Connect(address, port, ondata_callback, onstate_callback) |
| 21 | { |
37 | { |
| 22 | socket_id = SocketExport_Connect(address, port); |
38 | socket_id = SocketExport_Connect(address, port); |
| 23 | 39 | ||
| 24 | if (socket_id > 0) |
40 | if (socket_id > 0) |
| 25 | { |
41 | { |
| 26 | Socket_Connections[socket_id] = { "ondata" : ondata_callback, "onstate" : onstate_callback }; |
42 | Socket_Connections[socket_id] = { "ondata" : ondata_callback, "onstate" : onstate_callback }; |
| 27 | } |
43 | } |
| 28 | 44 | ||
| 29 | return socket_id; |
45 | return socket_id; |
| - | 46 | } |
|
| - | 47 | ||
| - | 48 | function Socket_StopServer(socket_id) |
|
| - | 49 | { |
|
| - | 50 | SocketExport_StopServer(socket_id); |
|
| - | 51 | ||
| - | 52 | delete Socket_Connections[socket_id]; |
|
| 30 | } |
53 | } |
| 31 | 54 | ||
| 32 | function Socket_Disconnect(socket_id) |
55 | function Socket_Disconnect(socket_id) |
| 33 | { |
56 | { |
| 34 | SocketExport_Disconnect(socket_id); |
57 | SocketExport_Disconnect(socket_id); |