Code

Updated sockets
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 30 Nov 2007 10:17:33 +0000 (10:17 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 30 Nov 2007 10:17:33 +0000 (10:17 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7949 594d385d-05f5-0310-b6e9-bd551577e9d8

contrib/socket_server/client.php
contrib/socket_server/server.php

index 64e37babfa99cc363225f2a388919eb6110d847b..e160a082b14be8daa4c26f5af76718892ea283b0 100755 (executable)
@@ -4,7 +4,7 @@
 error_reporting(E_ALL);
 
 echo "\n\nTry to connect";
-$sock = new Socket_Client("localhost","10000");
+$sock = new Socket_Client("localhost","10000",TRUE,1);
 if($sock->connected()){
        echo "... successful\n";
        echo "|--Reading welcome message : \n";
@@ -12,18 +12,24 @@ if($sock->connected()){
        
        /* Prepare a hunge bunch of data to be send */
        $data = "a";
-       for($i = 0 ; $i < (1024 * 1024); $i++){
+       for($i = 0 ; $i < (1024 * 4); $i++){
                $data .= "a";
        }
        echo "|--Sending ".strlen($data)."bytes of data to socket.\n";
        $sock->send($data);
+       echo "|--Done!\n";
        $sock->read();  
-       $sock->bytes_read();
        echo "|--".$sock->bytes_read()."bytes read.\n";
        echo "|--Sending 'exit' command to socket.\n";  
-       echo $sock->read();
-               
-
+       $sock->send("exit");
+       echo "|--Reading message:\n";
+       echo $sock->read()."\n";        
+       
+       echo "|--Closing connection.\n";
+       $sock->close(); 
+       echo "|--Done!\n";
+       echo "|--End\n\n";
+       
 }else{
        echo "... FAILED!\n";
 }
@@ -94,13 +100,13 @@ class Socket_Client
 
                        /* Check if there is something to read for us */
                        $read = array("0"=>$this->handle);      
-                       $num = stream_select($read,$write=NULL,$accept=NULL,1);
-
+                       $num = stream_select($read,$write=NULL,$accept=NULL,$this->timeout);
+                               
                        /* Read data if necessary */
-                       while($num){
-                               $str.= fread($this->handle, 1024);
+                       while($num && $this->b_data_send){
+                               $str.= fread($this->handle, 1024000);
                                $read = array("0"=>$this->handle);      
-                               $num = stream_select($read,$write=NULL,$accept=NULL,1);
+                               $num = stream_select($read,$write=NULL,$accept=NULL,$this->timeout);
                        }
                        $this->bytes_read = strlen($str);
                        $this->b_data_send = FALSE;
index 15ce8c660d31deb443b16b32656ea3b01b45f5e2..1c9a44b5595395df9d690c3310c738b4eff83bd7 100755 (executable)
@@ -98,14 +98,14 @@ Type some text here:\n");
                        }
 
                        $data = trim($data);
-                       echo "Client (".$clients[$i]['ipaddy'].") send : ".$data." \n";
+                       echo "Client (".$clients[$i]['ipaddy'].") send : ".substr($data,0,30)."... \n";
        
                        if($data == "exit"){
                                /* Close conenction */
-                               socket_write($clients[$i]['socket'],"Bye Bye! \n");
-                               echo "Client disconnected! ".$clients[$i]['ipaddy']."\n";
-                               unset($clients[$i]);
-                               continue;
+                               socket_write($clients[$i]['socket'],"Bye Bye!");
+                               socket_close($clients[$i]);
+                               echo "Client disconnected! bye bye!".$clients[$i]['ipaddy']."\n";
+#                              unset($clients[$i]);
                                
                        }else{
                                /* Send some data back to the client */