swoolewebSocketserverorclientexample

server:

创新互联建站致力于成都网站制作、成都网站建设、外贸营销网站建设,成都网站设计,集团网站建设等服务标准化,推过标准化降低中小企业的建站的成本,并持续提升建站的定制化服务水平进行质量交付,让企业网站从市场竞争中脱颖而出。 选择创新互联建站,就选择了安全、稳定、美观的网站建设服务!

$ws=newswoole_websocket_server('0.0.0.0',9502);

$ws->on('open',function($ws,$request) {
   var_dump($request->fd,$request->get,$request->server);
   $ws->push($request->fd,"hello world\");
});

$ws->on('message',function($ws,$frame) {
   echo"Message:{$frame->data}\";
   $ws->push($frame->fd,"server:{$frame->data}");
});

$ws->on('close',function($ws,$fd) {
   echo"client-{$fd} is closed\";
});

$ws->start();

client:

$cli=newswoole_http_client('127.0.0.1',9502);

$cli->on('message',function($_cli,$frame) {
   var_dump($frame);
});

$cli->upgrade('/',function($cli) {
   echo$cli->body;
   $cli->push("hello world");
});

分享标题:swoolewebSocketserverorclientexample
文章地址:http://azwzsj.com/article/jcohee.html