Skip to content

Commit

Permalink
Documentation, proper version bump in request
Browse files Browse the repository at this point in the history
  • Loading branch information
cboden committed Mar 17, 2016
1 parent 53aacc3 commit 5aa1b73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

[![Autobahn Testsuite](https://img.shields.io/badge/Autobahn-passing-brightgreen.svg)](http://socketo.me/reports/pawl/index.html)

An asynchronous PHP WebSocket client
An asynchronous WebSocket client in PHP

---
Using Pawl as a standalone app: Connect to an echo server, send a message, display output back, close connection.
#### Install via composer:
composer require ratchet/pawl

#### Usage
Pawl as a standalone app: Connect to an echo server, send a message, display output, close connection:
```php
<?php

Expand All @@ -23,7 +26,33 @@ Using Pawl as a standalone app: Connect to an echo server, send a message, displ
});
```

Using the components of Pawl: Requesting sub-protocols, and sending custom headers while using a specific React Event Loop.
---

#### Classes

There are 3 primary classes to be aware of and use in Pawl:

##### Connector:

Makes HTTP requests to servers returning a promise that, if successful, will resolve to a WebSocket object.
A connector is configured via its constructor and a request is made by invoking the class. Multiple connections can be established through a single connector. The invoke mehtod has 3 parameters:
* **$url**: String; A valid uri string (starting with ws:// or wss://) to connect to (also accepts PSR-7 Uri object)
* **$subProtocols**: Array; An optional indexed array of WebSocket sub-protocols to negotiate to the server with. The connection will fail if the client and server can not agree on one if any are provided
* **$headers**: Array; An optional associative array of additional headers requests to use when initiating the handshake. A common header to set is `Origin`

##### WebSocket:

This is the object used to interact with a WebSocket server. It has two methods: `send` and `close`.
It has two public properties: `request` and `response` which are PSR-7 objects representing the client and server side HTTP handshake headers used to establish the WebSocket connection.

##### Message:

This is the object received from a WebSocket server. It has a `__toString` method which is how most times you will want to access the data received.
If you need to do binary messaging you will most likely need to use methods on the object.

#### Example

A more in-depth example using explicit interfaces: Requesting sub-protocols, and sending custom headers while using a specific React Event Loop:
```php
<?php

Expand Down
2 changes: 1 addition & 1 deletion src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function generateRequest($url, array $subProtocols, array $headers) {
$uri = $uri->withPort('wss' === $scheme ? 443 : 80);
}

$headers += ['User-Agent' => 'Ratchet-Pawl/0.2'];
$headers += ['User-Agent' => 'Ratchet-Pawl/0.2.1'];

$request = array_reduce(array_keys($headers), function($request, $header) use ($headers) {
return $request->withHeader($header, $headers[$header]);
Expand Down

0 comments on commit 5aa1b73

Please sign in to comment.