public function testServerAcceptClient() { self::$server->onConnectPeer(function (Peer $peer) { self::$peer_accepted++; }); self::$server->listen(); }
public function testListen_shouldDieIfAttemptsLimit() { $server = new Server($this->createMockStore([[], [], ['test']])); $server->setDelay(0.1); $server->setAttemptsLimit(2); $events = $server->listen(time()); $this->assertEquals([], $events, 'Завершение работы при достижении attemptsLimit'); }
* Copyright (c) sk89q <http://sk89q.therisenrealm.com> * Licensed under the GNU General Public License v3 */ require 'config.php'; require 'server.php'; require 'shoutcast.php'; require 'audiosource.php'; require 'http.php'; set_time_limit(0); $Server = new Server(); $AudioSource = new AudioSource(); $AudioSource->bitrate = $CONFIG['bitrate']; $AudioSource->encoder = $CONFIG['encoder_path']; $AudioSource->metadata_interval = $CONFIG['metadata_interval']; $AudioSource->populate_playlist($CONFIG['music_dir']); $AudioSource->open_next_file(); $Shoutcast = new Shoutcast(); $Shoutcast->server =& $Server; $Shoutcast->source =& $AudioSource; $Shoutcast->metadata_interval = $CONFIG['metadata_interval']; $Shoutcast->server_name = $CONFIG['server_name']; $Shoutcast->server_genre = $CONFIG['server_genre']; $Shoutcast->server_url = $CONFIG['server_url']; $Shoutcast->server_public = $CONFIG['server_public']; $Shoutcast->hook_to_server(); $HTTP = new HTTP(); $HTTP->server =& $Server; $HTTP->shoutcast =& $Shoutcast; $HTTP->hook_to_server(); $Server->listen();
$address = trim(array_shift($args)); break; case "-d": $document_root = trim(array_shift($args)); break; case "--help": $help = true; break; case "--rewrite": $rewrite = true; break; } } if ($help) { print "Usage: {$script} [-p port] [-h host] [-d document_root] [--rewrite] [--help]\n"; print "\nCurrent settings:\n"; print "* Host - {$address}\n"; print "* Port - {$port}\n"; print "* Document Root - {$document_root}\n"; print "* Rewrite Rule - " . ($rewrite ? "On" : "Off") . "\n"; exit; } // Strip any trailing slash from the document root $document_root = preg_replace("!^(.*)/\$!", "\$1", $document_root); $server = new Server($address, $port); $server->document_root = $document_root; if ($rewrite) { $server->handler_options["rewrite"] = true; } $server->listen();
<?php include './config.php'; if ($argc != 3) { die("Usage: {$argv[0]} host port\n"); } $myServer = new Server($argv[1], $argv[2]); echo $myServer->showStatus(); $myServer->startUp(); echo $myServer->showStatus(); while (($string = $myServer->listen()) !== false) { echo getTimestamp() . " Got string of '{$string}'\n"; }
class Server extends \FastD\Swoole\Server\Tcp { /** * @param swoole_server $server * @param $fd * @param $data * @param $from_id * @return mixed */ public function doWork(swoole_server $server, $fd, $data, $from_id) { return 'hello server1'; } } class Server2 extends \FastD\Swoole\Server\Tcp { /** * @param swoole_server $server * @param $fd * @param $data * @param $from_id * @return mixed */ public function doWork(swoole_server $server, $fd, $data, $from_id) { return 'hello server2'; } } $server = new Server('tcp://127.0.0.1:9527'); $server->listen(new Server2('tcp://127.0.0.1:9528')); $server->start();