6 $socket = awcn_connect($ip, $port);
9 awcn_disconnect($socket);
11 function awcn_connect($ip, $port) {
12 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
13 if ($socket === false) {
14 echo "socket_create() failed: reason: "
15 . socket_strerror(socket_last_error()) . "\n";
19 echo "Attempting to connect to '$ip' on port '$port'...";
20 $result = socket_connect($socket, $ip, $port);
21 if ($result === false) {
22 echo "socket_connect() failed.\nReason: ($result) "
23 . socket_strerror(socket_last_error($socket)) . "\n";
30 function awcn_init($socket)
32 $msg = "\x00\x01DecoderV=1\n";
33 socket_write($socket, $msg, strlen($msg));
34 $res = awcn_read_response($socket);
35 socket_write($socket, "\x00\x02", 2);
38 function awcn_loop($socket)
41 $dbgmsg = awcn_read_response($socket);
42 //echo $dbgmsg . "\n";
43 awcn_handle_msg($dbgmsg);
46 function awcn_read_response($socket)
48 $res = socket_read($socket, 2048, PHP_NORMAL_READ);
49 return substr($res, 2, -1);
52 function awcn_disconnect($socket)
54 socket_write($socket, "\x00\x03", 2);
55 socket_close($socket);
58 function awcn_handle_msg($msg)
60 if (substr($msg, 0, 9) != '[DKANPROT') {
61 //unknown message type
64 $regex = '#^\\[DKANPROT-([^ ]+) ([0-9]+)\\] (.*)$#';
65 if (!preg_match($regex, $msg, $matches)) {
66 //message should always be that way
69 list(, $type, $someid, $details) = $matches;
71 if ($type != 'Info') {
72 //we only want info messages
73 var_dump($type . ': ' . $details);
76 //Vegw/Ets-Cref:[0xffef]/[0x64] - VEGW_SETUP from upper layer to internal destination: CGPN[**22]->CDPN[41],
78 $regex = '#CGPN\\[([^\\]]+)\\]->CDPN\\[([^\\]]+)\\]#';
79 if (preg_match($regex, $details, $matches)) {
80 var_dump('a call!', $matches);