@@ -30,6 +30,7 @@ handle multiple concurrent connections without blocking.
3030 * [ pause()] ( #pause )
3131 * [ resume()] ( #resume )
3232 * [ close()] ( #close )
33+ * [ Server] ( #server )
3334 * [ TcpServer] ( #tcpserver )
3435 * [ SecureServer] ( #secureserver )
3536 * [ LimitingServer] ( #limitingserver )
@@ -319,6 +320,101 @@ $server->close();
319320
320321Calling this method more than once on the same instance is a NO-OP.
321322
323+ ### Server
324+
325+ The ` Server ` class implements the [ ` ServerInterface ` ] ( #serverinterface ) and
326+ is responsible for accepting plaintext TCP/IP connections.
327+ It acts as a facade for the underlying [ ` TcpServer ` ] ( #tcpserver ) and follows
328+ its exact semantics.
329+
330+ ``` php
331+ $server = new Server(8080, $loop);
332+ ```
333+
334+ As above, the ` $uri ` parameter can consist of only a port, in which case the
335+ server will default to listening on the localhost address ` 127.0.0.1 ` ,
336+ which means it will not be reachable from outside of this system.
337+
338+ In order to use a random port assignment, you can use the port ` 0 ` :
339+
340+ ``` php
341+ $server = new Server(0, $loop);
342+ $address = $server->getAddress();
343+ ```
344+
345+ In order to change the host the socket is listening on, you can provide an IP
346+ address through the first parameter provided to the constructor, optionally
347+ preceded by the ` tcp:// ` scheme:
348+
349+ ``` php
350+ $server = new Server('192.168.0.1:8080', $loop);
351+ ```
352+
353+ If you want to listen on an IPv6 address, you MUST enclose the host in square
354+ brackets:
355+
356+ ``` php
357+ $server = new Server('[::1]:8080', $loop);
358+ ```
359+
360+ If the given URI is invalid, does not contain a port, any other scheme or if it
361+ contains a hostname, it will throw an ` InvalidArgumentException ` :
362+
363+ ``` php
364+ // throws InvalidArgumentException due to missing port
365+ $server = new Server('127.0.0.1', $loop);
366+ ```
367+
368+ If the given URI appears to be valid, but listening on it fails (such as if port
369+ is already in use or port below 1024 may require root access etc.), it will
370+ throw a ` RuntimeException ` :
371+
372+ ``` php
373+ $first = new Server(8080, $loop);
374+
375+ // throws RuntimeException because port is already in use
376+ $second = new Server(8080, $loop);
377+ ```
378+
379+ > Note that these error conditions may vary depending on your system and/or
380+ configuration.
381+ See the exception message and code for more details about the actual error
382+ condition.
383+
384+ Optionally, you can specify [ socket context options] ( http://php.net/manual/en/context.socket.php )
385+ for the underlying stream socket resource like this:
386+
387+ ``` php
388+ $server = new Server('[::1]:8080', $loop, array(
389+ 'backlog' => 200,
390+ 'so_reuseport' => true,
391+ 'ipv6_v6only' => true
392+ ));
393+ ```
394+
395+ > Note that available [ socket context options] ( http://php.net/manual/en/context.socket.php ) ,
396+ their defaults and effects of changing these may vary depending on your system
397+ and/or PHP version.
398+ Passing unknown context options has no effect.
399+
400+ Whenever a client connects, it will emit a ` connection ` event with a connection
401+ instance implementing [ ` ConnectionInterface ` ] ( #connectioninterface ) :
402+
403+ ``` php
404+ $server->on('connection', function (ConnectionInterface $connection) {
405+ echo 'Plaintext connection from ' . $connection->getRemoteAddress() . PHP_EOL;
406+
407+ $connection->write('hello there!' . PHP_EOL);
408+ …
409+ });
410+ ```
411+
412+ See also the [ ` ServerInterface ` ] ( #serverinterface ) for more details.
413+
414+ > Note that the ` Server ` class is a concrete implementation for TCP/IP sockets.
415+ If you want to typehint in your higher-level protocol implementation, you SHOULD
416+ use the generic [ ` ServerInterface ` ] ( #serverinterface ) instead.
417+
322418### TcpServer
323419
324420The ` TcpServer ` class implements the [ ` ServerInterface ` ] ( #serverinterface ) and
@@ -408,10 +504,6 @@ $server->on('connection', function (ConnectionInterface $connection) {
408504
409505See also the [ ` ServerInterface ` ] ( #serverinterface ) for more details.
410506
411- Note that the ` TcpServer ` class is a concrete implementation for TCP/IP sockets.
412- If you want to typehint in your higher-level protocol implementation, you SHOULD
413- use the generic [ ` ServerInterface ` ] ( #serverinterface ) instead.
414-
415507### SecureServer
416508
417509The ` SecureServer ` class implements the [ ` ServerInterface ` ] ( #serverinterface )
0 commit comments