http://code.google.com/p/phpws/
Description
websocket server and client library for php. works with the latest hybi specifications, as well the older hixie #76 specification used by older chrome versions and some flash fallback solutions.
This project was started to bring more interactive features to http://www.u2start.com/
DownloadsCurrently no downloads are available. Source and simple example available in GIT repository (see Source tab).
FeaturesServer
Hixie #76 and Hybi #12 protocol versions Flash client support (also serves XML policy file on the same port) See https://github.com/gimite/web-socket-js for a compatible Flash Client Native Firefox, Safari (iPod / iPhone as well), Chrome and IE10 support. With Flash Client every browser supporting Flash works as well (including IE6-9, Opera, Android and other older desktop browsers). Opera (Mobile) supports WebSockets natively but support has been disabled by default. Can be enabled in opera:config.立即学习“PHP免费学习笔记(深入)”;
Client
Hybi / Hixie76 support.立即学习“PHP免费学习笔记(深入)”;
Known Issues SSL support not well field tested. Lacks ORIGIN checking (can be implemented manually in onConnect using getHeaders(), just disconnect the user when you dont like the Origin header) No support for extension data from the HyBi specs. RequirementsServer
PHP 5.3 Open port for the server PHP OpenSSL module to run a server over a encrypted connection立即学习“PHP免费学习笔记(深入)”;
Client
PHP 5.3 Server that implements the HyBi (#8-#12) draft version PHP OpenSSL module to connect using SSL (wss:// uris)立即学习“PHP免费学习笔记(深入)”;
Server Example#!/php -q<?php// Run from command prompt > php demo.phprequire_once("websocket.server.php");/** * This demo resource handler will respond to all messages sent to /echo/ on the socketserver below * * All this handler does is echoing the responds to the user * @author Chris * */class DemoEchoHandler extends WebSocketUriHandler{ public function onMessage(IWebSocketConnection $user, IWebSocketMessage $msg){ $this->say("[ECHO] {$msg->getData()}"); // Echo $user->sendMessage($msg); } public function onAdminMessage(IWebSocketConnection $user, IWebSocketMessage $obj){ $this->say("[DEMO] Admin TEST received!"); $frame = WebSocketFrame::create(WebSocketOpcode::PongFrame); $user->sendFrame($frame); }}/** * Demo socket server. Implements the basic eventlisteners and attaches a resource handler for /echo/ urls. * * * @author Chris * */class DemoSocketServer implements IWebSocketServerObserver{ protected $debug = true; protected $server; public function __construct(){ $this->server = new WebSocketServer(0, 12345, 'superdupersecretkey'); $this->server->addObserver($this); $this->server->addUriHandler("echo", new DemoEchoHandler()); } public function onConnect(IWebSocketConnection $user){ $this->say("[DEMO] {$user->getId()} connected"); } public function onMessage(IWebSocketConnection $user, IWebSocketMessage $msg){ $this->say("[DEMO] {$user->getId()} says '{$msg->getData()}'"); } public function onDisconnect(IWebSocketConnection $user){ $this->say("[DEMO] {$user->getId()} disconnected"); } public function onAdminMessage(IWebSocketConnection $user, IWebSocketMessage $msg){ $this->say("[DEMO] Admin Message received!"); $frame = WebSocketFrame::create(WebSocketOpcode::PongFrame); $user->sendFrame($frame); } public function say($msg){ echo "$msg \r\n"; } public function run(){ $this->server->run(); }}// Start server$server = new DemoSocketServer(0,12345);$server->run();
The Client is not as interesting as the server and is mainly used to test the server
<?php require_once("websocket.client.php"); $input = "Hello World!"; $msg = WebSocketMessage::create($input); $client = new WebSocket("ws://127.0.0.1:12345/echo/"); $client->sendMessage($msg); // Wait for an incoming message $msg = $client->readMessage(); $client->close(); echo $msg->getData(); // Prints "Hello World!" when using the demo.php server
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号