Purpose of this Component

The IoServer should be the base of your application. This is the core of the events driven from client actions. It handles receiving new connections, reading/writing to those connections, closing the connections, and handles all errors from your application.

Note: This component is bundled within the App class.

Events triggered by this Component

  • onOpen (ConnectionInterface $conn) - A new client connection has been opened
  • onClose (ConnectionInterface $conn) - A client connection is about to, or has closed
  • onMessage (ConnectionInterface $from, string $message) - A data message has been received
  • onError (ConnectionInterface $from, Exception $error) - An error has occurred with a Connection

Configuration methods

  • void run() - Enter the event loop of your application and listen for incoming connections and data

Functions callable on Connections

  • send (string $message) - Send a message (string) to the client
  • close - Gracefully close the connection to the client

Parameters added to each Connection

(string $remoteAddress) - The address (IP Address) the user connected with
(int $resourceId) - An incremental number assigned when the connection is made

Wraps other components nicely

Wrapped by other components nicely

Typically, none. This should be the base of your application as it handles the direct communication and transport with clients.


// Your shell script
use Ratchet\Server\IoServer;

    $server = IoServer::factory(new MyApp, 8080); // Run your app on port 8080