2 define("NETCOM_PORT", 14001);
3 define("NETCOM_PORT_SSL", 14002);
6 // comms on this thing are very serial, the server are only capable of processing
7 // one thing at a time... for now
10 function __construct($am_i_a_server = false, $server_addr = "127.0.0.1")
12 // i have to set it to something, right?
13 $this->semKey = ftok(__FILE__, "p");
14 $this->encrypt = false;
16 $this->amserver = $am_i_a_server;
17 $this->server = $server_addr;
21 // initiates a bind if its a server, a connect if its a client
25 $this->listen_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
26 socket_bind($this->listen_socket, "127.0.0.1", NETCOM_PORT);
27 socket_listen($this->listen_socket);
30 $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
31 $res = socket_connect($this->socket, "127.0.0.1", NETCOM_PORT);
33 echo "fail on connect\n";
34 socket_close($this->socket);
41 function waitForConnection()
43 socket_listen($this->listen_socket);
44 $this->socket = socket_accept($this->listen_socket);
47 function sendMessage($message_array)
49 $datacomp = base64_encode(serialize($message_array));
50 $tosend = "PEN:$datacomp:INE";
52 socket_send($this->socket, $tosend, strlen($tosend), 0);
54 // get up to one meg of data - this is bad... i can feel this function
56 // TODO FIX THIS - its garbage code... im not really sure how to handle this really
57 // we need to read back as AS:data:EOD - i think it now does.. i hope, tho we need
61 function receiveMessage()
66 $size = socket_recv($this->socket, $recvd_a, 1024, 0);
68 if(preg_match("/.*\:INE$/", $recvd)) {
69 // we have a full string... break out
76 // first check we got something that makes sense
77 if(preg_match("/^PEN:.*:INE/", $recvd) < 1) {
78 socket_close($this->socket);
79 echo "Returned data is not in right format\n";
80 // we have a problem jim
84 $xps = explode(":", $recvd);
86 $component = unserialize(base64_decode($xps[1]));
99 private $listen_socket;
100 private $listen_socket_ssl;
105 * PEN:base64_enoded data:INE