-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.php
More file actions
30 lines (21 loc) · 808 Bytes
/
Copy pathclient.php
File metadata and controls
30 lines (21 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
use Porter\Client;
use Porter\Payload;
use Workerman\Connection\AsyncTcpConnection;
require __DIR__ . '/../../vendor/autoload.php';
// use localhost instead 0.0.0.0 for connect in local env
$client = new Client('ws://localhost:3737');
$client->getWorker()::$logFile = __DIR__ . '/client.log';
$client->onConnected(function (AsyncTcpConnection $connection) use ($client) {
$client->send('hello');
});
$client->onDisconnected(function (AsyncTcpConnection $connection) use ($client) {
$client->send('goodbye');
});
$client->onError(function (AsyncTcpConnection $connection, $code, $message) use ($client) {
$client->send('whoops');
});
$client->on('ping', function (AsyncTcpConnection $connection, Payload $payload, Client $client) {
$client->send('pong');
});
$client->listen();