// first we want to fork into the background like all good daemons should
//$pid = pcntl_fork();
+
// uncomment this bit and comment the fork above to stop it going into the background
$pid = 0;
// 3) main server continues.
// a forked process thingy should be fully self contained and capable of dealing
// with "problems", i.e. the parent doesnt want to have to clean up children
+
+ /* TCP TEST
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
- global $TCP_PORT_NUMBER;
+
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER, 0666 | 'IPC_CREAT');
+ */
// Here goes the tcp equivalent
- /*
+ global $TCP_PORT_NUMBER;
$res = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- socket_bind($res, "127.0.0.1", 10056);
+ socket_bind($res, "127.0.0.1", $TCP_PORT_NUMBER);
socket_listen($res);
+ echo "am now listneing\n";
while(true) {
$data_socket = socket_accept($res);
while($continue) {
$size = socket_recv($data_socket, $recvd_a, 1024, 0);
$recvd .= $recvd_a;
- if(preg_match("/.*\:EOD$/", $recvd) {
+ if(preg_match("/.*\:EOD$/", $recvd)) {
// we have a full string... break out
$continue = false;
break;
$msg_type = $component["type"];
$msg = $component["data"];
+ echo "I now have a message of $msg_type\n";
+ echo "with data:\n";
+ print_r($msg);
+ echo "eof\n";
// the switch should now set a $data_returned value that gets bundled up and sent back to the client
// HERES WHERE THE SWITCH GOES
// ******
}
// otherwise return to the accept loop
}
-
- */
+}
+ /*
$myga = new gaasGA();
global $myga;
break;
}
+
}
+
}
+*/
?>
// 2) timeouts and locking
// io think this function should now "work" more or less as is
- function sendReceiveTcp($message_type, $message) {
+ function sendReceive($message_type, $message) {
// yeah... this is totally gunna work
global $TCP_PORT_NUMBER;
$datacomp = base64_encode(serialize($msg));
$tosend = "AC:$datacomp:EOD";
- socket_send($socket, $tosend, strlen($tosend));
+ socket_send($socket, $tosend, strlen($tosend), 0);
// get up to one meg of data - this is bad... i can feel this function
// hurting alot
while($continue) {
$size = socket_recv($socket, $recvd_a, 1024, 0);
$recvd .= $recvd_a;
- if(preg_match("/.*\:EOD$/", $recvd) {
+ if(preg_match("/.*\:EOD$/", $recvd)) {
// we have a full string... break out
$continue = false;
break;
return $component["data"];
}
- function sendReceive($message_type, $message) {
+ function sendReceiveIPC($message_type, $message) {
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
if(!isset($MSG_QUEUE_KEY_ID_CLIENT)) $MSG_QUEUE_KEY_ID_CLIENT = "189751073"; // ftok is not ok!
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
-if(!isset($TCP_PORT_NUMBER)) $TCP_PORT_NUMBER = 21416;
+if(!isset($TCP_PORT_NUMBER)) $TCP_PORT_NUMBER = 21446;
global $TCP_PORT_NUMBER;
define("MSG_AUTH_USER_TOKEN", 1);