-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathecho.php
More file actions
35 lines (26 loc) · 898 Bytes
/
echo.php
File metadata and controls
35 lines (26 loc) · 898 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
31
32
33
34
35
<?php
use Ratchet\ConnectionInterface;
require __DIR__ . '/../vendor/autoload.php';
class EchoEcho implements \Ratchet\MessageComponentInterface {
public function onOpen(ConnectionInterface $conn) {
}
public function onMessage(ConnectionInterface $from, $msg) {
$from->send($msg);
$now = date(DATE_RFC2822);
$headers = $from->WebSocket->request->getHeader('User-Agent');
echo "{$now} -- id:{$from->resourceId} -- {$from->remoteAddress} -- {$headers} -- ({$msg})\n";
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
$server = \Ratchet\Server\IoServer::factory(
new \Ratchet\Http\HttpServer(
new \Ratchet\WebSocket\WsServer(
new EchoEcho
)
),
9000
);
$server->run();