Skip to content

Commit d19e579

Browse files
committed
Update readme
1 parent b4692e6 commit d19e579

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,44 @@ Supported functions:
1515

1616
## Usage
1717

18+
### Directly Create A Client
19+
20+
You can directly create a `Gos\Component\WebSocketClient\Wamp\ClientInterface` instance by creating a new `Gos\Component\WebSocketClient\Wamp\Client` object. The constructor has two mandatory requirements; the server host and port. You may review the [`Client class constructor`](/src/Wamp/Client.php) to see all arguments.
21+
1822
```php
23+
<?php
1924
use Gos\Component\WebSocketClient\Wamp\Client;
2025

21-
$client = new Client('127.0.0.1', '8080');
26+
$client = new Client('127.0.0.1', 8080);
27+
```
28+
29+
### Through The Factory
30+
31+
A `Gos\Component\WebSocketClient\Wamp\ClientFactoryInterface` is available to create client instances as well. The default `Gos\Component\WebSocketClient\Wamp\ClientFactory` supports a PSR-3 logger and will automatically inject it into the client if one is present.
32+
33+
```php
34+
<?php
35+
use Gos\Component\WebSocketClient\Wamp\ClientFactory;
36+
37+
$factory = new ClientFactory(['host' => '127.0.0.1', 'port' => 8080]);
38+
$client = $factory->createConnection();
39+
```
40+
41+
### Interact With Server
42+
43+
Once you have created a client, you can connect and interact with your websocket server.
44+
45+
```php
46+
<?php
47+
use Gos\Component\WebSocketClient\Wamp\ClientFactory;
48+
49+
$factory = new ClientFactory(['host' => '127.0.0.1', 'port' => 8080]);
50+
$client = $factory->createConnection();
51+
2252
$sessionId = $client->connect();
2353

2454
// Establish a prefix on server
25-
$client->prefix("calc", "http://example.com/simple/calc#");
55+
$client->prefix('calc', 'http://example.com/simple/calc#');
2656

2757
// You can send an arbitrary number of arguments
2858
$client->call('calc', 12, 14, 15);
@@ -35,11 +65,10 @@ $client->call('calc', $data);
3565
$exclude = [$sessionId]; // No sense in sending the payload to ourselves
3666
$eligible = []; // List of other clients ids that are eligible to receive this payload
3767

38-
// $payload can be scalar or array
39-
$client->publish('topic', [], $exclude, $eligible);
68+
$client->publish('topic', '', $exclude, $eligible);
4069

4170
// Publish an event
42-
$client->event('topic', []);
71+
$client->event('topic', '');
4372
$client->disconnect();
4473
```
4574

0 commit comments

Comments
 (0)