All pastes #835879 Raw Edit

Someone

public text v1 · immutable
#835879 ·published 2007-12-29 02:26 UTC
rendered paste body
<?php

set_time_limit(0);
ob_implicit_flush();

class server {
	private $socket;
	private $clients = array();
	
	public function server() {
		$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
		echo "IP: " . ($ip = "0.0.0.0") . "\n";
		echo "PORT: " . ($port = 27015) . "\n";
		echo socket_bind($this->socket, $ip, $port) ? "Socket bound to $ip:$port\n" : "ERROR: Could not bind the socket to $ip:$port\n";
		echo socket_listen($this->socket) ? "Listening...\n" : "ERROR: Could not listen...\n";
		
		echo "Entering the main loop\n";
		while (true) {
			$r = array($this->socket);
			$w = NULL;
			$e = NULL;
			if (socket_select($r, $w, $e, 0) > 0) {
				$clients[] = socket_accept($this->socket);
				echo " ### A client was added! ### \n";
			}
			usleep(1000);	
		}
		
	}
} $server = new server();

?>