Design Philosophy

Components: Architecting your Application

The core of Ratchet is made up of Components. Each component implements a version of the ComponentInterface. If you follow that link you can see each of the classes that implement ComponentInterface.

Each class is instantiated when the script is launched, then enters an event loop, where I/O listens and calls the class on top of it. (it does not trigger a global event, it passes the event on to one class attached to [below] it).

An event is triggered at the top of the table (seen below) from a client on the other side of the socket. The client connection associated with the event then propagates up the structure along with any information sent.

Each class defines which interface it accepts, then propagating its own events. This structure allows developers to add or subtract class components to create different functionality. For example, one may want to add a logging component between WebSocket and WAMP to log raw JSON messages received by the client.

Below is an example of an Application put together using various components. You can see how by adding more layers, Components are able to extend and further define raw data into more specific events. As seen below WAMP accepts a data event, it then parses that data (JSON) and propagates its own events based on the data received.

Component Class Event triggered by Client (JavaScript)
I/O (socket transport) open close data error
HTTP Protocol Handler open close data error
WebSocket Protocol Handler open close data error
Session Provider open close data error
WAMP Protocol Handler open close publish subscribe unsubscribe call prefix error
(your) Application open close publish subscribe unsubscribe call prefix error

Connections: Objects Passed through your Application Components

With your application architecture set up and instantiated Resources are then passed through your application. When events are triggered by the base (IoServer) and propagated up to your application a Connection object is sent representing the client on the other end of the wire. These Connection objects are used to interact with the client and are passed through your application.