File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ and [`Stream`](https://github.com/reactphp/stream) components.
1414* [ Usage] ( #usage )
1515 * [ Server] ( #server )
1616 * [ ConnectionInterface] ( #connectioninterface )
17+ * [ getRemoteAddress()] ( #getremoteaddress )
1718* [ Install] ( #install )
1819* [ License] ( #license )
1920
@@ -26,7 +27,7 @@ $loop = React\EventLoop\Factory::create();
2627
2728$socket = new React\Socket\Server($loop);
2829$socket->on('connection', function (ConnectionInterface $conn) {
29- $conn->write("Hello there !\n");
30+ $conn->write("Hello " . $conn->getRemoteAddress() . " !\n");
3031 $conn->write("Welcome to this amazing server!\n");
3132 $conn->write("Here's a tip: don't say anything.\n");
3233
@@ -115,6 +116,19 @@ $connection->close();
115116For more details, see the
116117[ ` DuplexStreamInterface ` ] ( https://github.com/reactphp/stream#duplexstreaminterface ) .
117118
119+ #### getRemoteAddress()
120+
121+ The ` getRemoteAddress(): ?string ` method returns the remote address
122+ (client IP) where this connection has been established from.
123+
124+ ``` php
125+ $ip = $connection->getRemoteAddress();
126+ ```
127+
128+ It will return the remote address as a string value.
129+ If the remote address can not be determined or is unknown at this time (such as
130+ after the connection has been closed), it MAY return a ` NULL ` value instead.
131+
118132## Install
119133
120134The recommended way to install this library is [ through Composer] ( http://getcomposer.org ) .
Original file line number Diff line number Diff line change 2626 */
2727interface ConnectionInterface extends DuplexStreamInterface
2828{
29+ /**
30+ * Returns the remote address (client IP) where this connection has been established from
31+ *
32+ * @return string|null remote address (client IP) or null if unknown
33+ */
2934 public function getRemoteAddress ();
3035}
You can’t perform that action at this time.
0 commit comments