Skip to content

Commit 1941744

Browse files
committed
Documentation for getRemoteAddress()
1 parent 993cf51 commit 1941744

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff 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();
115116
For 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

120134
The recommended way to install this library is [through Composer](http://getcomposer.org).

src/ConnectionInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
*/
2727
interface 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
}

0 commit comments

Comments
 (0)