if ($p === false) { return; } // Вырежем команду $cmd = substr($Connection->ReadBUF, 0, $p); $Connection->ReadBUF = substr($Connection->ReadBUF, $p + 1); if (trim($cmd) == 'quit') { //echo "quit detach\r\n"; $this->ConnectionManager->detach($Connection); } else { $this->WriteToAll($Connection->id . ":" . $cmd . "\r\n"); } } } class TestHTTPProtocol extends tSocketProtocol { function onData($Connection) { $Connection->Write("HTTP/1.1 200 OK\r\nContenth-type: text/html; charset=UTF-8\r\n\r\nOK"); $Connection->Close(); } } $server = new tSocketServer(); $server->attachProtocol(new MyProtocol()); // accepting connections on port 4111 and 4112 if ($server->Bind('127.0.0.1', 4111)) { if ($server->Bind('127.0.0.1', 4112)) { echo "Binded\n"; $server->Start(); } }
<?php /* * $Id: Example.php,v 1.2 2009-04-19 04:56:28 root Exp $ */ require_once realpath(dirname(__FILE__)) . '/SocketServer.php'; $server = new tSocketServer(); $server->attachProtocol(new tSocketProtocol()); if ($server->Bind('127.0.0.1', 4111)) { echo "Binded\n"; $server->Start(); }