Each client connection has a property with the initial HTTP request information.
With 0.4 this property name has changed and its API has been replaced with a PSR-7 Request object.
public function onOpen(ConnectionInterface $conn) { $ip = (string)$conn->WebSocket->request->getHeader('X-Forwarded-For'); }With 0.4 this should change to:
public function onOpen(ConnectionInterface $conn) { $ip = $conn->httpRequest->getHeader('X-Forwarded-For'); }
Note: The 0.3 Guzzle API returned a Header object which had a __toString method whereas the the PSR-7 interface returns a string.
If you previously were using the getCookie method of the request object it is no longer available in PSR-7. You will need to call getHeader('Cookie') and parse the string value yourself. One way to do this is with the FIG Cookies library.
With Ratchet/0.4 binary messages are now optionally supported. A large effort was made to keep backwards compatability with 0.3 while introducing binary messages. This effort came at a tradeoff of cognitive complexity for those wishing to use the new binary API feature. If you do not wish to support binary messages nothing has changed for you in 0.4. string values will continue to be sent to your onMessage methods inside your component.
If you wish to accept binary messages from clients your component interface will change slightly. Instead of implementing a Ratchet\MessageComponentInterface it should now implement a \Ratchet\WebSocket\MessageComponentInterface. Your component will now received MessageInterface objects instead of strings:
use Ratchet\ConnectionInterface; use Ratchet\WebSocket\MessageComponentInterface; use Ratchet\RFC6455\Messaging\MessageInterface; class MyComponent implements MessageComponentInterface { public function onMessage(ConnectionInterface $from, MessageInterface $msg) { } ... }
The Session component used to implement the WsServerInterface. It now (more logically) implements the HttpServerInterface as sessions are an HTTP concept, not a WebSocket concept. This may or may not affect your code if you're using SessionProvider; you now must have it wrapped by HttpServer:
$server = new IoServer( new HttpServer( new SessionProvider( new WsServer(new MyApp), $provider ) ) );
Ratchet has long supported unsolicited ping requests but with 0.4 is now supports an (optional) active hearbeat monitor using WebSocket ping/pong frames. If you're using the App class it will be enabled automatically. If you're composing components yourself here's how to enable it on a 30 second timer:
<php $wsServer = new Ratchet\WebSocket\WsServer(new MyApp); $server = Ratchet\Server\IoServer::factory( new Ratchet\Http\HttpServer( $wsServer ) ); $wsServer->enableKeepAlive($server->loop, 30); $server->run();