-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoload.php
34 lines (28 loc) · 1 KB
/
autoload.php
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
// Test 3
class ChartServer implements Ratchet\MessageComponentInterface
{
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(Ratchet\ConnectionInterface $conn) {
$this->clients->attach($conn);
echo "New connection has arrived! ({$conn->resourceId})\n";
}
public function onClose(Ratchet\ConnectionInterface $conn) {
$this->clients->detach($conn);
echo "Connection {$conn->resourceId} has disconnected\n";
}
public function onError(Ratchet\ConnectionInterface $conn, Exception $e) {
echo "An error has occurred Bro: {$e->getMessage()}\n";
$conn->close();
}
public function onMessage(Ratchet\ConnectionInterface $from, $msg) {
foreach ($this->clients as $client) {
if ($from !== $client) {
// Send the received message to all clients except the sender
$client->send($msg);
}
}
}
}