Skip to content

Commit 1cb3bed

Browse files
committed
Mark TcpServer and SecureServer as advanced usage
1 parent 2a56537 commit 1cb3bed

File tree

4 files changed

+36
-46
lines changed

4 files changed

+36
-46
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ handle multiple concurrent connections without blocking.
3131
* [resume()](#resume)
3232
* [close()](#close)
3333
* [Server](#server)
34-
* [TcpServer](#tcpserver)
35-
* [SecureServer](#secureserver)
36-
* [LimitingServer](#limitingserver)
37-
* [getConnections()](#getconnections)
34+
* [Advanced server usage](#advanced-server-usage)
35+
* [TcpServer](#tcpserver)
36+
* [SecureServer](#secureserver)
37+
* [LimitingServer](#limitingserver)
38+
* [getConnections()](#getconnections)
3839
* [Client usage](#client-usage)
3940
* [ConnectorInterface](#connectorinterface)
4041
* [connect()](#connect)
@@ -55,8 +56,8 @@ Here is a server that closes the connection if you send it anything:
5556

5657
```php
5758
$loop = React\EventLoop\Factory::create();
59+
$socket = new React\Socket\Server('127.0.0.1:8080', $loop);
5860

59-
$socket = new React\Socket\TcpServer(8080, $loop);
6061
$socket->on('connection', function (ConnectionInterface $conn) {
6162
$conn->write("Hello " . $conn->getRemoteAddress() . "!\n");
6263
$conn->write("Welcome to this amazing server!\n");
@@ -322,10 +323,9 @@ Calling this method more than once on the same instance is a NO-OP.
322323

323324
### Server
324325

325-
The `Server` class implements the [`ServerInterface`](#serverinterface) and
326-
is responsible for accepting plaintext TCP/IP connections.
327-
It acts as a facade for the underlying [`TcpServer`](#tcpserver) and follows
328-
its exact semantics.
326+
The `Server` class is the main class in this package that implements the
327+
[`ServerInterface`](#serverinterface) and allows you to accept incoming
328+
streaming connections, such as plaintext TCP/IP or secure TLS connection streams.
329329

330330
```php
331331
$server = new Server(8080, $loop);
@@ -461,7 +461,9 @@ See also the [`ServerInterface`](#serverinterface) for more details.
461461
If you want to typehint in your higher-level protocol implementation, you SHOULD
462462
use the generic [`ServerInterface`](#serverinterface) instead.
463463

464-
### TcpServer
464+
### Advanced server usage
465+
466+
#### TcpServer
465467

466468
The `TcpServer` class implements the [`ServerInterface`](#serverinterface) and
467469
is responsible for accepting plaintext TCP/IP connections.
@@ -550,7 +552,7 @@ $server->on('connection', function (ConnectionInterface $connection) {
550552

551553
See also the [`ServerInterface`](#serverinterface) for more details.
552554

553-
### SecureServer
555+
#### SecureServer
554556

555557
The `SecureServer` class implements the [`ServerInterface`](#serverinterface)
556558
and is responsible for providing a secure TLS (formerly known as SSL) server.
@@ -630,7 +632,7 @@ If you use a custom `ServerInterface` and its `connection` event does not
630632
meet this requirement, the `SecureServer` will emit an `error` event and
631633
then close the underlying connection.
632634

633-
### LimitingServer
635+
#### LimitingServer
634636

635637
The `LimitingServer` decorator wraps a given `ServerInterface` and is responsible
636638
for limiting and keeping track of open connections to this server instance.
@@ -697,7 +699,7 @@ $server->on('connection', function (ConnectionInterface $connection) {
697699
});
698700
```
699701

700-
#### getConnections()
702+
##### getConnections()
701703

702704
The `getConnections(): ConnectionInterface[]` method can be used to
703705
return an array with all currently active connections.

examples/01-echo.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,22 @@
88
//
99
// You can also run a secure TLS echo server like this:
1010
//
11-
// $ php examples/01-echo.php 8000 examples/localhost.pem
11+
// $ php examples/01-echo.php tls://127.0.0.1:8000 examples/localhost.pem
1212
// $ openssl s_client -connect localhost:8000
1313

1414
use React\EventLoop\Factory;
15-
use React\Socket\TcpServer;
15+
use React\Socket\Server;
1616
use React\Socket\ConnectionInterface;
17-
use React\Socket\SecureServer;
1817

1918
require __DIR__ . '/../vendor/autoload.php';
2019

2120
$loop = Factory::create();
2221

23-
$server = new TcpServer(isset($argv[1]) ? $argv[1] : 0, $loop);
24-
25-
// secure TLS mode if certificate is given as second parameter
26-
if (isset($argv[2])) {
27-
$server = new SecureServer($server, $loop, array(
28-
'local_cert' => $argv[2]
29-
));
30-
}
22+
$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop, array(
23+
'tls' => array(
24+
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
25+
)
26+
));
3127

3228
$server->on('connection', function (ConnectionInterface $conn) {
3329
echo '[connected]' . PHP_EOL;

examples/02-chat-server.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,23 @@
88
//
99
// You can also run a secure TLS chat server like this:
1010
//
11-
// $ php examples/02-chat-server.php 8000 examples/localhost.pem
11+
// $ php examples/02-chat-server.php tls://127.0.0.1:8000 examples/localhost.pem
1212
// $ openssl s_client -connect localhost:8000
1313

1414
use React\EventLoop\Factory;
15-
use React\Socket\TcpServer;
15+
use React\Socket\Server;
1616
use React\Socket\ConnectionInterface;
17-
use React\Socket\SecureServer;
1817
use React\Socket\LimitingServer;
1918

2019
require __DIR__ . '/../vendor/autoload.php';
2120

2221
$loop = Factory::create();
2322

24-
$server = new TcpServer(isset($argv[1]) ? $argv[1] : 0, $loop);
25-
26-
// secure TLS mode if certificate is given as second parameter
27-
if (isset($argv[2])) {
28-
$server = new SecureServer($server, $loop, array(
29-
'local_cert' => $argv[2]
30-
));
31-
}
23+
$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop, array(
24+
'tls' => array(
25+
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
26+
)
27+
));
3228

3329
$server = new LimitingServer($server, null);
3430

examples/03-benchmark.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,24 @@
1111
//
1212
// You can also run a secure TLS benchmarking server like this:
1313
//
14-
// $ php examples/03-benchmark.php 8000 examples/localhost.pem
14+
// $ php examples/03-benchmark.php tls://127.0.0.1:8000 examples/localhost.pem
1515
// $ openssl s_client -connect localhost:8000
1616
// $ echo hello world | openssl s_client -connect localhost:8000
1717
// $ dd if=/dev/zero bs=1M count=1000 | openssl s_client -connect localhost:8000
1818

1919
use React\EventLoop\Factory;
20-
use React\Socket\TcpServer;
20+
use React\Socket\Server;
2121
use React\Socket\ConnectionInterface;
22-
use React\Socket\SecureServer;
2322

2423
require __DIR__ . '/../vendor/autoload.php';
2524

2625
$loop = Factory::create();
2726

28-
$server = new TcpServer(isset($argv[1]) ? $argv[1] : 0, $loop);
29-
30-
// secure TLS mode if certificate is given as second parameter
31-
if (isset($argv[2])) {
32-
$server = new SecureServer($server, $loop, array(
33-
'local_cert' => $argv[2]
34-
));
35-
}
27+
$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop, array(
28+
'tls' => array(
29+
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
30+
)
31+
));
3632

3733
$server->on('connection', function (ConnectionInterface $conn) use ($loop) {
3834
echo '[connected]' . PHP_EOL;

0 commit comments

Comments
 (0)