Skip to content

ConnectionInterface should extend DuplexStreamInterface + documentation #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Documentation for ConnectionInterface
  • Loading branch information
clue committed Nov 13, 2016
commit 993cf51283cea26908e6b25961e19335d0cd7f58
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and [`Stream`](https://github.com/reactphp/stream) components.
* [Quickstart example](#quickstart-example)
* [Usage](#usage)
* [Server](#server)
* [Connection](#connection)
* [ConnectionInterface](#connectioninterface)
* [Install](#install)
* [License](#license)

Expand Down Expand Up @@ -66,18 +66,55 @@ $loop->run();

### Server

The server can listen on a port and will emit a `connection` event whenever a
client connects.
The `Server` class is responsible for listening on a port and waiting for new connections.

### Connection
Whenever a client connects, it will emit a `connection` event with a connection
instance implementing [`ConnectionInterface`](#connectioninterface):

The `Connection` is a duplex (readable and writable) [`Stream`](https://github.com/reactphp/stream).
The incoming connection represents the server-side end of the connection.
```php
$server->on('connection', function (ConnectionInterface $connection) {
});
```

### ConnectionInterface

The `ConnectionInterface` is used to represent any incoming connection.

An incoming connection is a duplex stream (both readable and writable) that
implements React's
[`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface)
and contains only a single additional property, the remote address (client IP)
where this connection has been established from.

> Note that this interface is only to be used to represent the server-side end
of an incoming connection.
It MUST NOT be used to represent an outgoing connection in a client-side context.
If you want to establish an outgoing connection,
use the [`SocketClient`](https://github.com/reactphp/socket-client) component instead.

Because the `ConnectionInterface` implements the underlying
[`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface)
you can use any of its events and methods as usual:

```php
$connection->on('data', function ($chunk) {
echo $data;
});

$conenction->on('close', function () {
echo 'closed';
});

$connection->write($data);
$connection->end($data = null);
$connection->close();
// …
```

For more details, see the
[`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).

## Install

The recommended way to install this library is [through Composer](http://getcomposer.org).
Expand Down
5 changes: 5 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use React\Stream\Stream;

/**
* The actual connection implementation for ConnectionInterface
*
* @see ConnectionInterface
*/
class Connection extends Stream implements ConnectionInterface
{
public function handleData($stream)
Expand Down
20 changes: 20 additions & 0 deletions src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

use React\Stream\DuplexStreamInterface;

/**
* Any incoming connection is represented by this interface.
*
* An incoming connection is a duplex stream (both readable and writable) that
* implements React's DuplexStreamInterface and contains only a single
* additional property, the remote address (client IP) where this connection has
* been established from.
*
* Note that this interface is only to be used to represent the server-side end
* of an incoming connection.
* It MUST NOT be used to represent an outgoing connection in a client-side
* context.
* If you want to establish an outgoing connection,
* use React's SocketClient component instead.
*
* Because the `ConnectionInterface` implements the underlying
* `DuplexStreamInterface` you can use any of its events and methods as usual.
*
* @see DuplexStreamInterface
*/
interface ConnectionInterface extends DuplexStreamInterface
{
public function getRemoteAddress();
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy