Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • Connector
  • DnsConnector
  • LimitingServer
  • SecureConnector
  • SecureServer
  • Server
  • TcpConnector
  • TimeoutConnector
  • UnixConnector

Interfaces

  • ConnectionInterface
  • ConnectorInterface
  • ServerInterface
  • Overview
  • Namespace
  • Class
  • Tree

Interface ConnectionInterface

Any incoming and outgoing connection is represented by this interface, such as a normal TCP/IP connection.

An incoming or outgoing connection is a duplex stream (both readable and writable) that implements React's [DuplexStreamInterface](https://github.com/reactphp/stream#duplexstreaminterface). It contains additional properties for the local and remote address (client IP) where this connection has been established to/from.

Most commonly, instances implementing this ConnectionInterface are emitted by all classes implementing the [ServerInterface](#serverinterface) and used by all classes implementing the [ConnectorInterface](#connectorinterface).

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 $chunk; });

$connection->on('end', function () { echo 'ended'; });

$connection->on('error', function (Exception $e) { echo 'error: ' . $e->getMessage(); });

$connection->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).

React\Socket\ConnectionInterface implements React\Stream\DuplexStreamInterface
Namespace: React\Socket
See: React\Stream\DuplexStreamInterface
See: React\Socket\ServerInterface
See: React\Socket\ConnectorInterface
Located at ConnectionInterface.php
Methods summary
public ?string
# getRemoteAddress( )

Returns the remote address (client IP and port) where this connection has been established with

Returns the remote address (client IP and port) where this connection has been established with

`php $address = $connection->getRemoteAddress(); echo 'Connection with ' . $address . PHP_EOL; `

If the remote address can not be determined or is unknown at this time (such as after the connection has been closed), it MAY return a NULL value instead.

Otherwise, it will return the full remote address as a string value. If this is a TCP/IP based connection and you only want the remote IP, you may use something like this:

`php $address = $connection->getRemoteAddress(); $ip = trim(parse_url('tcp://' . $address, PHP_URL_HOST), '[]'); echo 'Connection with ' . $ip . PHP_EOL; `

Returns

?string
remote address (client IP and port) or null if unknown
public ?string
# getLocalAddress( )

Returns the full local address (client IP and port) where this connection has been established with

Returns the full local address (client IP and port) where this connection has been established with

`php $address = $connection->getLocalAddress(); echo 'Connection with ' . $address . PHP_EOL; `

If the local address can not be determined or is unknown at this time (such as after the connection has been closed), it MAY return a NULL value instead.

Otherwise, it will return the full local address as a string value.

This method complements the [getRemoteAddress()](#getremoteaddress) method, so they should not be confused.

If your Server instance is listening on multiple interfaces (e.g. using the address 0.0.0.0), you can use this method to find out which interface actually accepted this connection (such as a public or local interface).

If your system has multiple interfaces (e.g. a WAN and a LAN interface), you can use this method to find out which interface was actually used for this connection.

Returns

?string
local address (client IP and port) or null if unknown

See

React\Socket\ConnectionInterface::getRemoteAddress()
Methods inherited from React\Stream\WritableStreamInterface
close(), end(), isWritable(), write()
Methods inherited from Evenement\EventEmitterInterface
emit(), listeners(), on(), once(), removeAllListeners(), removeListener()
Methods inherited from React\Stream\ReadableStreamInterface
isReadable(), pause(), pipe(), resume()
Ratchet API documentation generated by ApiGen 2.8.0