| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
12年前发布

WebSocket 的 PHP 实现 - phpwebsocket

从名字上也可看出,这是一个 WebSocket 的 PHP 实现。

示例客户端代码:

var host = "ws://localhost:12345/websocket/server.php";  try{    socket = new WebSocket(host);    log('WebSocket - status '+socket.readyState);    socket.onopen    = function(msg){ log("Welcome - status "+this.readyState); };    socket.onmessage = function(msg){ log("Received: "+msg.data); };    socket.onclose   = function(msg){ log("Disconnected - status "+this.readyState); };  }  catch(ex){ log(ex); }
示例服务器端代码:
log("Handshaking...");  list($resource,$host,$origin) = getheaders($buffer);  $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .             "Upgrade: WebSocket\r\n" .             "Connection: Upgrade\r\n" .             "WebSocket-Origin: " . $origin . "\r\n" .             "WebSocket-Location: ws://" . $host . $resource . "\r\n" .             "\r\n";  $handshake = true;  socket_write($socket,$upgrade.chr( ),strlen($upgrade.chr( )));

项目主页:http://www.open-open.com/lib/view/home/1338512348120

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1338512348120.html
WebSocket WebSocket 开发