summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6a3633a)
raw | patch | inline | side by side (parent: 6a3633a)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 30 Nov 2007 10:17:33 +0000 (10:17 +0000) | ||
committer | hickert <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 | patch | blob | history | |
contrib/socket_server/server.php | patch | blob | history |
index 64e37babfa99cc363225f2a388919eb6110d847b..e160a082b14be8daa4c26f5af76718892ea283b0 100755 (executable)
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";
/* 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";
}
/* 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)
}
$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 */