55use React \Stream \DuplexStreamInterface ;
66
77/**
8- * Any incoming connection is represented by this interface.
8+ * Any incoming and outgoing connection is represented by this interface,
9+ * such as a normal TCP/IP connection.
910 *
10- * An incoming connection is a duplex stream (both readable and writable) that
11- * implements React's DuplexStreamInterface.
11+ * An incoming or outgoing connection is a duplex stream (both readable and
12+ * writable) that implements React's
13+ * [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).
1214 * It contains additional properties for the local and remote address (client IP)
13- * where this connection has been established from.
15+ * where this connection has been established to/ from.
1416 *
15- * Note that this interface is only to be used to represent the server-side end
16- * of an incoming connection.
17- * It MUST NOT be used to represent an outgoing connection in a client-side
18- * context.
19- * If you want to establish an outgoing connection,
20- * use React's SocketClient component instead.
17+ * Most commonly, instances implementing this `ConnectionInterface` are emitted
18+ * by all classes implementing the [`ServerInterface`](#serverinterface) and
19+ * used by all classes implementing the [`ConnectorInterface`](#connectorinterface).
2120 *
2221 * Because the `ConnectionInterface` implements the underlying
23- * `DuplexStreamInterface` you can use any of its events and methods as usual:
22+ * [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface)
23+ * you can use any of its events and methods as usual:
2424 *
2525 * ```php
2626 * $connection->on('data', function ($chunk) {
4949 * [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).
5050 *
5151 * @see DuplexStreamInterface
52+ * @see ServerInterface
53+ * @see ConnectorInterface
5254 */
5355interface ConnectionInterface extends DuplexStreamInterface
5456{
5557 /**
56- * Returns the remote address (client IP and port) where this connection has been established from
58+ * Returns the remote address (client IP and port) where this connection has been established with
5759 *
5860 * ```php
5961 * $address = $connection->getRemoteAddress();
60- * echo 'Connection from ' . $address . PHP_EOL;
62+ * echo 'Connection with ' . $address . PHP_EOL;
6163 * ```
6264 *
6365 * If the remote address can not be determined or is unknown at this time (such as
@@ -70,19 +72,19 @@ interface ConnectionInterface extends DuplexStreamInterface
7072 * ```php
7173 * $address = $connection->getRemoteAddress();
7274 * $ip = trim(parse_url('tcp://' . $address, PHP_URL_HOST), '[]');
73- * echo 'Connection from ' . $ip . PHP_EOL;
75+ * echo 'Connection with ' . $ip . PHP_EOL;
7476 * ```
7577 *
7678 * @return ?string remote address (client IP and port) or null if unknown
7779 */
7880 public function getRemoteAddress ();
7981
8082 /**
81- * Returns the full local address (client IP and port) where this connection has been established to
83+ * Returns the full local address (client IP and port) where this connection has been established with
8284 *
8385 * ```php
8486 * $address = $connection->getLocalAddress();
85- * echo 'Connection to ' . $address . PHP_EOL;
87+ * echo 'Connection with ' . $address . PHP_EOL;
8688 * ```
8789 *
8890 * If the local address can not be determined or is unknown at this time (such as
@@ -97,6 +99,10 @@ public function getRemoteAddress();
9799 * the address `0.0.0.0`), you can use this method to find out which interface
98100 * actually accepted this connection (such as a public or local interface).
99101 *
102+ * If your system has multiple interfaces (e.g. a WAN and a LAN interface),
103+ * you can use this method to find out which interface was actually
104+ * used for this connection.
105+ *
100106 * @return ?string local address (client IP and port) or null if unknown
101107 * @see self::getRemoteAddress()
102108 */
0 commit comments