clientws1.php 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/5/23
  6. * Time: 17:42
  7. */
  8. define('START_TIME', microtime(true));
  9. require __DIR__ . '/../vendor/autoload.php';
  10. \app\lib\boot::init();
  11. use app\lib\wclient\WebSocketClient ;
  12. $client = new WebSocketClient();
  13. $client->on("open",function ($client) {
  14. $fd = $client->getTcpClient()->sock;
  15. echo "fd: $fd is open\n";
  16. $msg = '{"cmd":"test","act":"broad","data":"你好,朋友们!","time":1558492565,"token":"aasasfa"}';
  17. $client->send($msg);
  18. });
  19. $client->on("message", function ($client, $frame) {
  20. $fd = $client->getTcpClient()->sock;
  21. echo "fd: $fd received: {$frame->data}\n";
  22. });
  23. $client->on("close", function ($client) {
  24. $fd = $client->getTcpClient()->sock;
  25. echo "fd: $fd is closed\n";
  26. });
  27. $client->connect("192.168.2.200", 9090);