summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3bfdc3f)
raw | patch | inline | side by side (parent: 3bfdc3f)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 30 Nov 2007 10:31:43 +0000 (10:31 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 30 Nov 2007 10:31:43 +0000 (10:31 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7952 594d385d-05f5-0310-b6e9-bd551577e9d8
contrib/socket_server/client.php | patch | blob | history | |
contrib/socket_server/server.php | patch | blob | history |
index 89600670a38f037e8fb4274092dbe23a24670141..bdf01e26b2ef1ddb4d3af075c863490d05928cb4 100755 (executable)
/* Prepare a hunge bunch of data to be send */
$data = "a";
- for($i = 0 ; $i < (1024 * 4); $i++){
+ for($i = 0 ; $i < (1024 * 1); $i++){
$data .= "a";
}
echo "|--Sending ".strlen($data)."bytes of data to socket.\n";
index 1c9a44b5595395df9d690c3310c738b4eff83bd7..b6be267415a4a3f2f9806afb019c4fd34fa8bea6 100755 (executable)
#!/usr/bin/php5 -q
<?php
+error_reporting(E_ALL);
+
//IP to bind to, use 0 for all
$bind_ip = 0;
$bind_port = 10000;
// Max clients
-$max_clients = 10;
+$max_clients = 3;
$clients = array('0' => array('socket' => $socket));
-echo "\nServer startet on port : ".$port."
+echo "\nServer startet on port : ".$bind_port."
You may use telnet to connect to the server
";
/* Create an array of sockets to read from */
$read[0] = $socket;
for($i=1;$i<count($clients)+1;$i++) {
- if($clients[$i] != NULL) {
+ if(isset($clients[$i] ) && $clients[$i] != NULL) {
$read[$i+1] = $clients[$i]['socket'];
}
}
/* Check if socket has send data to the server
*/
- if(in_array($clients[$i]['socket'],$read)) {
+ if(isset($clients[$i]) && in_array($clients[$i]['socket'],$read)) {
/* Read socket data */
$data = @socket_read($clients[$i]['socket'],1024000, PHP_NORMAL_READ);
if($data == "exit"){
/* Close conenction */
socket_write($clients[$i]['socket'],"Bye Bye!");
- socket_close($clients[$i]);
+ @socket_close($clients[$i]);
echo "Client disconnected! bye bye!".$clients[$i]['ipaddy']."\n";
-# unset($clients[$i]);
-
}else{
/* Send some data back to the client */
$data = base64_encode($data);