2 namespace callnotifier;
8 public function __construct($config, $handler)
10 $this->config = $config;
11 $this->handler = $handler;
16 $this->connect($this->config->host, $this->config->port);
22 public function connect($ip, $port)
24 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
25 if ($socket === false) {
26 echo "socket_create() failed: reason: "
27 . socket_strerror(socket_last_error()) . "\n";
31 echo "Attempting to connect to '$ip' on port '$port'...";
32 $result = socket_connect($socket, $ip, $port);
33 if ($result === false) {
34 echo "socket_connect() failed.\nReason: ($result) "
35 . socket_strerror(socket_last_error($socket)) . "\n";
40 $this->socket = $socket;
45 $msg = "\x00\x01DecoderV=1\n";
46 socket_write($this->socket, $msg, strlen($msg));
47 $res = $this->read_response();
48 socket_write($this->socket, "\x00\x02", 2);
54 $dbgmsg = $this->read_response();
55 //echo $dbgmsg . "\n";
56 $this->handler->handle($dbgmsg);
60 function read_response()
62 $res = socket_read($this->socket, 2048, PHP_NORMAL_READ);
63 return substr($res, 2, -1);
68 socket_write($this->socket, "\x00\x03", 2);
69 socket_close($this->socket);