recoding the pengine intercomms class for more "what we want"
authorpaulr <me@pjr.cc>
Sun, 20 Mar 2011 16:28:12 +0000 (03:28 +1100)
committerpaulr <me@pjr.cc>
Sun, 20 Mar 2011 16:28:12 +0000 (03:28 +1100)
type functionality

lib/interComms.php

index 1e7507f..5f77261 100644 (file)
@@ -18,7 +18,7 @@ define("NETCOM_PORT_SSL", 14002);
 
 class netCom {
        
-       function __construct($am_i_a_server = false, $server_addr = "127.0.0.1")
+       function __construct($am_i_a_server = false, $server_addr = "127.0.0.1", $secure = true)
        {
                global $storeLocation;
                
@@ -70,65 +70,32 @@ class netCom {
        }
        
        // initiates a bind if its a server, a connect if its a client
-       function go()
+       function go($callback = "")
        {
                if($this->amserver) {
                        echo "i am a server, bind!\n";
                        $this->listen_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-                       $this->listen_socket_ssl = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-                       socket_bind($this->listen_socket, "127.0.0.1", NETCOM_PORT);
-                       socket_listen($this->listen_socket);
-                       socket_bind($this->listen_socket_ssl, "127.0.0.1", NETCOM_PORT_SSL);
-                       socket_listen($this->listen_socket_ssl);
-                       echo "bound\n";
+                       if($this->secure_socket) {
+                               socket_bind($this->listen_socket, $this->server, NETCOM_PORT_SSL);
+                               socket_listen($this->listen_socket);
+                       } else {
+                               socket_bind($this->listen_socket, $this->server, NETCOM_PORT);
+                               socket_listen($this->listen_socket);
+                       }
+                       // here we fork our server
                } else {
                        echo "I am a client, connect!\n";
-                       $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-                       $res = socket_connect($this->socket, "127.0.0.1", NETCOM_PORT_SSL);
-                       $this->secure_socket = true;
-                       if(!$res) {
-                               echo "fail on connect\n";
-                               socket_close($this->socket);
-                               return false;
-                       }
-                       echo "connected\n";
-                       
-                       // now handle secure handshake;
                        if($this->secure_socket) {
-                               echo "begin handshake\n";
-                               $msg = $this->receiveMessage();
-                               echo "got msg:\n";
-                               print_r($msg);
-                               echo "\n";
+                               $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+                               $res = socket_connect($this->socket, $this->server, NETCOM_PORT_SSL);
+                       } else {
+                               $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+                               $res = socket_connect($this->socket, $this->server, NETCOM_PORT);
                                
                        }
                }
        }
        
-       function waitForConnection()
-       {
-               echo "in wait for connection\n";
-               socket_listen($this->listen_socket);
-               $this->socket = socket_accept($this->listen_socket);
-               $this->secure_socket = false;
-               echo "exit wait for connection\n";
-       }
-
-       function waitForSecureConnection()
-       {
-               echo "in wait for secure connection\n";
-               socket_listen($this->listen_socket_ssl);
-               $this->socket = socket_accept($this->listen_socket_ssl);
-               $this->secure_socket = true;
-               
-               // now do negotiate
-               if($this->secure_socket) {
-                       $arg[0] = $this->key_pub;
-                       $this->sendMessage($arg);
-               }
-               
-               echo "exit wait for connection\n";
-       }
        
        function sendMessage($message_array)
        {               
@@ -197,9 +164,7 @@ class netCom {
        private $semKey;
        private $amserver;
        private $socket;
-       private $socket_ssl;
        private $listen_socket;
-       private $listen_socket_ssl;
        private $key_priv;
        private $key_pub;
        private $secure_socket;