Subversion Repositories HomeAutomation

Rev

Rev 1651 | Rev 1962 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1651 runge 1
 
1959 runge 2
var Socket_Connections = {};
1651 runge 3
 
1959 runge 4
var SOCKET_STATE_CONNECTED      = 0x00;
5
var SOCKET_STATE_DISCONNECTED   = 0x01;
6
var SOCKET_STATE_ACCEPTED       = 0x02;
7
 
1651 runge 8
function Socket_OnNewData(socket_id, data)
9
{
10
    if (Socket_Connections[socket_id])
11
    {
12
        Socket_Connections[socket_id]["ondata"](socket_id, data);
13
    }
14
}
15
 
16
function Socket_OnNewState(socket_id, state)
17
{
18
    if (Socket_Connections[socket_id])
19
    {
20
        Socket_Connections[socket_id]["onstate"](socket_id, state);
21
    }
22
}
23
 
1959 runge 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;
34
}
35
 
1651 runge 36
function Socket_Connect(address, port, ondata_callback, onstate_callback)
37
{
38
    socket_id = SocketExport_Connect(address, port);
39
 
40
    if (socket_id > 0)
41
    {
42
        Socket_Connections[socket_id] = { "ondata" : ondata_callback, "onstate" : onstate_callback };
43
    }
44
 
45
    return socket_id;
46
}
47
 
1959 runge 48
function Socket_StopServer(socket_id)
49
{
50
  SocketExport_StopServer(socket_id);
51
 
52
  delete Socket_Connections[socket_id];
53
}
54
 
1651 runge 55
function Socket_Disconnect(socket_id)
56
{
57
    SocketExport_Disconnect(socket_id);
58
 
59
    delete Socket_Connections[socket_id];
60
}
61
 
62
function Socket_Send(socket_id, data)
63
{
64
    SocketExport_Send(socket_id, data);
65
}