Page 1 of 1

socket programming, multi-client support pleasee!!!

Posted: Sun Mar 07, 2004 1:54 pm
by Cruzado_Mainfrm
ok, heres my code, it only allows one client to be connected, if there's another, the other one has to wait until the first client closes the connection, also there's a problem that i'm having problem to solve, if the client connects and closes the telnet window without typing the command 'disconnect;' the connection somehow keeps opened...

Code: Select all

<?php
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($socket,'bluealien',23);
socket_listen($socket);
while($connection = socket_accept($socket))
{
unset($close);
socket_write($connection,"Connected to server at ".$_SERVER['REMOTE_ADDR']."!\r\n>");
	do
	{
	$input = @socket_read($connection, 128,0));
	$command .= $input;
	$position = strrpos($command,';');
		if ($position == strlen($command)-1 && strlen($command)>1) {
			switch($command) {
			case 'disconnect;':
			echo "\nClient disconnected.";
			socket_close($connection);
			break;
			case 'msconfig;':
			echo "\nRunning MSCONFIG.";
			exec('msconfig');
			break;
			default:
			socket_write($connection,"\n\rInvalid Command: $command\n\r>",strlen("\n\rInvalid Command: $command\n\r>"));
			break;			
			}
		unset($command);
		}
	flush();
	} while (true);
}
socket_close($socket);
?>
can someone help me make this script accept more than one connection at a time???

Posted: Wed Mar 10, 2004 2:35 pm
by Cruzado_Mainfrm
anyone? :cry: