标签:浏览器 网络协议 UNC opcode websocket sed hand nis OLE
1、WebSocket协议是基于tcp协议的一种新型的网络协议。它的实现了浏览器与服务器全双工通信-----允许服务器主动发送信息给客户端
2、http协议通信只能有客户端发送请求
$server = new Swoole\WebSocket\Server("0.0.0.0", 9501); $server->on(‘open‘, function (Swoole\WebSocket\Server $server, $request) { echo "server: handshake success with fd{$request->fd}\n"; }); $server->on(‘message‘, function (Swoole\WebSocket\Server $server, $frame) { echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n"; $server->push($frame->fd, "this is server"); }); $server->on(‘close‘, function ($ser, $fd) { echo "client {$fd} closed\n"; }); $server->start();
<h1>swooler-websocket测试</h1> <script> var wsurl = "域名:端口号"; var websocket = new WebSocket(weurl); //实例对象onopen属性 websocket.ononnpen = function(evt){ console.log("connected-swoole-connect"); } websocket.onmessage = function (evt){ console.log("server-return-data:"+etv,data); } websocket.onclose = functin(evt){ console.log("close"); } websocket.onerror = function(evt,e){ console.log("server-error"_etv.data); } </script>
标签:浏览器 网络协议 UNC opcode websocket sed hand nis OLE
原文地址:https://www.cnblogs.com/hanmengya/p/10936317.html