-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
28 lines (20 loc) · 910 Bytes
/
main.php
File metadata and controls
28 lines (20 loc) · 910 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
<?php
use Muyu\WebSocket\Connection;
use Muyu\WebSocket\Message;
use Muyu\WebSocket\Packet;
use Muyu\WebSocket\Server;
require __DIR__ . '/vendor/autoload.php';
$server = new Server();
$server->on('open', function(Connection $client) use ($server) {
echo 'client connect, id: ' . $client->id() . ' total count: ' . count($server->clients()), PHP_EOL;
});
$server->on('close', function(Connection $client) use ($server) {
echo 'client close , id: ' . $client->id() . ' total count: ' . count($server->clients()), PHP_EOL;
});
$server->on('message', function(Connection $client, Message $message) use ($server) {
$server->sendMessage($client, Packet::MSG_TYPE_TXT, 'get ' . $message->content());
});
$server->on('send', function(Connection $client, Message $message) use ($server) {
echo 'client id ' . $client->id() . ' send length ' . $message->length(), PHP_EOL;
});
$server->start();