@@ -8,6 +8,10 @@ The socket component provides a more usable interface for a socket-layer
88server based on the [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop )
99and [ ` Stream ` ] ( https://github.com/reactphp/stream ) components.
1010
11+ > The master branch contains the code for the upcoming 0.5 release.
12+ For the code of the current stable 0.4.x release, checkout the
13+ [ 0.4 branch] ( https://github.com/reactphp/socket-client/tree/0.4 ) .
14+
1115** Table of Contents**
1216
1317* [ Quickstart example] ( #quickstart-example )
@@ -16,7 +20,7 @@ and [`Stream`](https://github.com/reactphp/stream) components.
1620 * [ connection event] ( #connection-event )
1721 * [ error event] ( #error-event )
1822 * [ getPort()] ( #getport )
19- * [ shutdown ()] ( #shutdown )
23+ * [ close ()] ( #close )
2024 * [ Server] ( #server )
2125 * [ SecureServer] ( #secureserver )
2226 * [ ConnectionInterface] ( #connectioninterface )
@@ -124,16 +128,16 @@ echo 'Server listening on port ' . $port . PHP_EOL;
124128It will return the port number or ` NULL ` if it is unknown (not applicable to
125129this server socket or already closed).
126130
127- #### shutdown ()
131+ #### close ()
128132
129- The ` shutdown (): void` method can be used to
133+ The ` close (): void` method can be used to
130134shut down this listening socket.
131135
132136This will stop listening for new incoming connections on this socket.
133137
134138``` php
135139echo 'Shutting down server socket' . PHP_EOL;
136- $server->shutdown ();
140+ $server->close ();
137141```
138142
139143Calling this method more than once on the same instance is a NO-OP.
@@ -156,6 +160,22 @@ provided to the constructor:
156160$server = new Server('192.168.0.1:8080', $loop);
157161```
158162
163+ Optionally, you can specify [ socket context options] ( http://php.net/manual/en/context.socket.php )
164+ for the underlying stream socket resource like this:
165+
166+ ``` php
167+ $server = new Server('[::1]:8080', $loop, array(
168+ 'backlog' => 200,
169+ 'so_reuseport' => true,
170+ 'ipv6_v6only' => true
171+ ));
172+ ```
173+
174+ > Note that available [ socket context options] ( http://php.net/manual/en/context.socket.php ) ,
175+ their defaults and effects of changing these may vary depending on your system
176+ and/or PHP version.
177+ Passing unknown context options has no effect.
178+
159179Whenever a client connects, it will emit a ` connection ` event with a connection
160180instance implementing [ ` ConnectionInterface ` ] ( #connectioninterface ) :
161181
@@ -271,17 +291,27 @@ For more details, see the
271291
272292#### getRemoteAddress()
273293
274- The ` getRemoteAddress(): ?string ` method returns the remote address
275- (client IP) where this connection has been established from.
294+ The ` getRemoteAddress(): ?string ` method returns the full remote address
295+ (client IP and port ) where this connection has been established from.
276296
277297``` php
278- $ip = $connection->getRemoteAddress();
298+ $address = $connection->getRemoteAddress();
299+ echo 'Connection from ' . $address . PHP_EOL;
279300```
280301
281- It will return the remote address as a string value.
282302If the remote address can not be determined or is unknown at this time (such as
283303after the connection has been closed), it MAY return a ` NULL ` value instead.
284304
305+ Otherwise, it will return the full remote address as a string value.
306+ If this is a TCP/IP based connection and you only want the remote IP, you may
307+ use something like this:
308+
309+ ``` php
310+ $address = $connection->getRemoteAddress();
311+ $ip = trim(parse_url('tcp://' . $address, PHP_URL_HOST), '[]');
312+ echo 'Connection from ' . $ip . PHP_EOL;
313+ ```
314+
285315## Install
286316
287317The recommended way to install this library is [ through Composer] ( http://getcomposer.org ) .
@@ -290,7 +320,7 @@ The recommended way to install this library is [through Composer](http://getcomp
290320This will install the latest supported version:
291321
292322``` bash
293- $ composer require react/socket:^0.4.5
323+ $ composer require react/socket:^0.4.6
294324```
295325
296326More details about version upgrades can be found in the [ CHANGELOG] ( CHANGELOG.md ) .
@@ -306,10 +336,10 @@ manually specify the root package version like this:
306336$ COMPOSER_ROOT_VERSION=` git describe --abbrev=0` composer install
307337```
308338
309- To run the test suite, you need PHPUnit. Go to the project root and run:
339+ To run the test suite, go to the project root and run:
310340
311341``` bash
312- $ phpunit
342+ $ php vendor/bin/ phpunit
313343```
314344
315345## License
0 commit comments