6 $socket = awcn_connect($ip, $port);
9 awcn_disconnect($socket);
12 function awcn_connect($ip, $port) {
13 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
14 if ($socket === false) {
15 echo "socket_create() failed: reason: "
16 . socket_strerror(socket_last_error()) . "\n";
20 echo "Attempting to connect to '$ip' on port '$port'...";
21 $result = socket_connect($socket, $ip, $port);
22 if ($result === false) {
23 echo "socket_connect() failed.\nReason: ($result) "
24 . socket_strerror(socket_last_error($socket)) . "\n";
31 function awcn_init($socket)
33 $msg = "\x00\x01DecoderV=1\n";
34 socket_write($socket, $msg, strlen($msg));
35 $res = awcn_read_response($socket);
36 socket_write($socket, "\x00\x02", 2);
39 function awcn_loop($socket)
42 $dbgmsg = awcn_read_response($socket);
43 //echo $dbgmsg . "\n";
44 awcn_handle_msg($dbgmsg);
47 function awcn_read_response($socket)
49 $res = socket_read($socket, 2048, PHP_NORMAL_READ);
50 return substr($res, 2, -1);
53 function awcn_disconnect($socket)
55 socket_write($socket, "\x00\x03", 2);
56 socket_close($socket);
59 function awcn_handle_msg($msg)
61 if (substr($msg, 0, 9) != '[DKANPROT') {
62 //unknown message type
65 $regex = '#^\\[DKANPROT-([^ ]+) ([0-9]+)\\] (.*)$#';
66 if (!preg_match($regex, $msg, $matches)) {
67 //message should always be that way
70 list(, $type, $someid, $details) = $matches;
72 if ($type != 'Info') {
73 //we only want info messages
74 var_dump($type . ': ' . $details);
77 //Vegw/Ets-Cref:[0xffef]/[0x64] - VEGW_SETUP from upper layer to internal destination: CGPN[**22]->CDPN[41],
79 $regex = '#CGPN\\[([^\\]]+)\\]->CDPN\\[([^\\]]+)\\]#';
80 if (preg_match($regex, $details, $matches)) {
81 var_dump('a call!', $matches);