| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/5/23
- * Time: 17:42
- */
- define('START_TIME', microtime(true));
- require __DIR__ . '/../vendor/autoload.php';
- \app\lib\boot::init();
- use app\lib\wclient\WebSocketClient ;
- $client = new WebSocketClient();
- $client->on("open",function ($client) {
- $fd = $client->getTcpClient()->sock;
- echo "fd: $fd is open\n";
- $msg = '{"cmd":"test","act":"broad","data":"你好,朋友们!","time":1558492565,"token":"aasasfa"}';
- $client->send($msg);
- });
- $client->on("message", function ($client, $frame) {
- $fd = $client->getTcpClient()->sock;
- echo "fd: $fd received: {$frame->data}\n";
- });
- $client->on("close", function ($client) {
- $fd = $client->getTcpClient()->sock;
- echo "fd: $fd is closed\n";
- });
- $client->connect("192.168.2.200", 9090);
|