From 260519f4cebefd44efe6d559f57dc2dfbfea757a Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 30 Nov 2007 10:17:33 +0000 Subject: [PATCH] Updated sockets git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7949 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/socket_server/client.php | 28 +++++++++++++++++----------- contrib/socket_server/server.php | 10 +++++----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/contrib/socket_server/client.php b/contrib/socket_server/client.php index 64e37babf..e160a082b 100755 --- a/contrib/socket_server/client.php +++ b/contrib/socket_server/client.php @@ -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; diff --git a/contrib/socket_server/server.php b/contrib/socket_server/server.php index 15ce8c660..1c9a44b55 100755 --- a/contrib/socket_server/server.php +++ b/contrib/socket_server/server.php @@ -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 */ -- 2.30.2