1.0.0
Changes since RC2
- Removed header methods from
Connection. Now theResponseobject is available withConnection::getResponse(), which provides access to the response headers and other response data. - Removed the
connector()function, so there is no longer a globalConnectorobject. - Fixed
Handshake::withHeaders()to remove all prior set headers as expected. - Added
ConnectContextparameter toconnect()function. ConnectionExceptionnow extendsHttpExceptionfromamphp/http-client.
Upgrading from v0.2.x to v1.0
This library has been refactored to use the new amphp/websocket library containing components that can be shared between server and clients.
The simplest way to use this library is with the connect() function to initiate a WebSocket connection.
$connection = yield Amp\Websocket\Client\connect('ws://localhost:1337/broadcast');
yield $connection->send('Hello!');
/** @var Amp\Websocket\Message $message */
while ($message = yield $connection->receive()) {
$payload = yield $message->buffer();
// $payload now contains the entire message content
yield $connection->send('Received message with length ' . strlen($payload));
}Custom request headers and connections options can be set using the Handshake class and passing this object to connect() instead of a string URI. Connection behavior can be further customized by using an instance of Connector to establish a connection instead of the connect() function.
WebSocket clients are now represented by Connection, which extends the Client object from amphp/websocket. This object contains several methods for getting information about the client, fetching the headers returned in the server response, and sending/receiving messages.