socket programming, multi-client support pleasee!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

socket programming, multi-client support pleasee!!!

Post 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???
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

anyone? :cry:
Post Reply