@@ -34,6 +34,7 @@ handle multiple concurrent connections without blocking.
3434 * [ Advanced server usage] ( #advanced-server-usage )
3535 * [ TcpServer] ( #tcpserver )
3636 * [ SecureServer] ( #secureserver )
37+ * [ UnixServer] ( #unixserver )
3738 * [ LimitingServer] ( #limitingserver )
3839 * [ getConnections()] ( #getconnections )
3940* [ Client usage] ( #client-usage )
@@ -255,7 +256,8 @@ If the address can not be determined or is unknown at this time (such as
255256after the socket has been closed), it MAY return a ` NULL ` value instead.
256257
257258Otherwise, it will return the full address (URI) as a string value, such
258- as ` tcp://127.0.0.1:8080 ` , ` tcp://[::1]:80 ` or ` tls://127.0.0.1:443 ` .
259+ as ` tcp://127.0.0.1:8080 ` , ` tcp://[::1]:80 ` , ` tls://127.0.0.1:443 `
260+ ` unix://example.sock ` or ` unix:///path/to/example.sock ` .
259261Note that individual URI components are application specific and depend
260262on the underlying transport protocol.
261263
@@ -342,6 +344,7 @@ Calling this method more than once on the same instance is a NO-OP.
342344The ` Server ` class is the main class in this package that implements the
343345[ ` ServerInterface ` ] ( #serverinterface ) and allows you to accept incoming
344346streaming connections, such as plaintext TCP/IP or secure TLS connection streams.
347+ Connections can also be accepted on Unix domain sockets.
345348
346349``` php
347350$server = new Server(8080, $loop);
@@ -373,6 +376,13 @@ brackets:
373376$server = new Server('[::1]:8080', $loop);
374377```
375378
379+ To listen on a Unix domain socket (UDS) path, you MUST prefix the URI with the
380+ ` unix:// ` scheme:
381+
382+ ``` php
383+ $server = new Server('unix:///tmp/server.sock', $loop);
384+ ```
385+
376386If the given URI is invalid, does not contain a port, any other scheme or if it
377387contains a hostname, it will throw an ` InvalidArgumentException ` :
378388
@@ -648,6 +658,43 @@ If you use a custom `ServerInterface` and its `connection` event does not
648658meet this requirement, the ` SecureServer ` will emit an ` error ` event and
649659then close the underlying connection.
650660
661+ #### UnixServer
662+
663+ The ` UnixServer ` class implements the [ ` ServerInterface ` ] ( #serverinterface ) and
664+ is responsible for accepting connections on Unix domain sockets (UDS).
665+
666+ ``` php
667+ $server = new UnixServer('/tmp/server.sock', $loop);
668+ ```
669+
670+ As above, the ` $uri ` parameter can consist of only a socket path or socket path
671+ prefixed by the ` unix:// ` scheme.
672+
673+ If the given URI appears to be valid, but listening on it fails (such as if the
674+ socket is already in use or the file not accessible etc.), it will throw a
675+ ` RuntimeException ` :
676+
677+ ``` php
678+ $first = new UnixServer('/tmp/same.sock', $loop);
679+
680+ // throws RuntimeException because socket is already in use
681+ $second = new UnixServer('/tmp/same.sock', $loop);
682+ ```
683+
684+ Whenever a client connects, it will emit a ` connection ` event with a connection
685+ instance implementing [ ` ConnectionInterface ` ] ( #connectioninterface ) :
686+
687+ ``` php
688+ $server->on('connection', function (ConnectionInterface $connection) {
689+ echo 'New connection' . PHP_EOL;
690+
691+ $connection->write('hello there!' . PHP_EOL);
692+ …
693+ });
694+ ```
695+
696+ See also the [ ` ServerInterface ` ] ( #serverinterface ) for more details.
697+
651698#### LimitingServer
652699
653700The ` LimitingServer ` decorator wraps a given ` ServerInterface ` and is responsible
0 commit comments