php 实现websockets客户端

php 实现websockets客户端,需要利用swoole(参考文档:
https://wiki.swoole.com/#/) require “WebSocketClient.php”; $client = new WebSocketClient(); $client->connect(“127.0.01”, 9501); $client->on(“open”, function ($client) { $fd = $client->getTcpClient()->sock; echo “fd: $fd is open\n”; $msg = [‘data’ =>”发送消息” ]; $client->send(json_encode($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”; return; }); $client->onClose($client);  

友情提示:点赞熊源码网http://www.dianzanxiong.com点赞熊源码网 » php 实现websockets客户端
分享到:
赞(0)
广告位820*80