12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\common\workman;
- use Workerman\Worker;
- class WebSocketServer
- {
- protected $worker;
-
- public function __construct()
- {
- }
-
- public function start()
- {
- $host="websocket://0.0.0.0:23456";
- $this->worker=new Worker($host);
- $this->worker->count=4;
- $this->run();
- }
-
- private function run()
- {
- $this->worker->onMessage = function ($connection, $data) {
-
- $connection->send('hello world,i am server');
-
- $tlv=new Tlv();
- $result=$tlv->Read($data);
- echo "[tlv]".date("Y-m-d H:i:s:");
- print_r( $result);
- echo "\n";
- };
- Worker::runAll();
- }
- }
|