forked from ghedipunk/PHP-Websockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlsserver.php
41 lines (25 loc) · 971 Bytes
/
tlsserver.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
35
36
37
38
39
40
41
#!/usr/bin/env php
<?php
namespace Phpws;
if (in_array('perf', $GLOBALS['argv'])) define('NOOUTPUT', 1);
define('SERVER_NAME', 'ghedipunk/PHP-Websockets-0.0~fr0.2tls');
require_once(__DIR__ . '/src/bootstrap.php');
class MyApplication extends \Gpws\Core\Application {
public function onMessage(\Gpws\Interfaces\Client $client, \Gpws\Interfaces\Message $message) {
$content = $message->getContent();
$binary = $message->getType() == $message::TYPE_BINARY;
if (!defined('NOOUTPUT')) printf('[App] New message (Length: %d Binary == %d)%s', strlen($content), $binary, PHP_EOL);
$client->queueMessage($message);
}
}
$myApp = new MyApplication();
$ws = new \Gpws\Core\Server(
array(
'EventLoopClass' => '\Gpws\EventLoop\StreamSelectLoop',
'ServerSocketClass' => '\Gpws\Socket\SecureStreamListenSocket',
'ClientSocketClass' => '\Gpws\Socket\SecureStreamClientSocket',
)
);
$ws->bind('0.0.0.0', 6110);
$ws->registerApp('/', $myApp);
$ws->run();