首页 后端开发 php教程 php websocket

php websocket

Jun 23, 2016 pm 02:37 PM
php websocket

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/

Downloads

Currently no downloads are available. Source and simple example available in GIT repository (see Source tab).

Features

Server

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.

Client

Hybi / Hixie76 support.

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. Requirements

Server

PHP 5.3 Open port for the server PHP OpenSSL module to run a server over a encrypted connection

Client

PHP 5.3 Server that implements the HyBi (#8-#12) draft version PHP OpenSSL module to connect using SSL (wss:// uris)

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();
登录后复制
Client Example

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
登录后复制

?> 

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PHP WebSocket开发实例:如何实现特定功能的演示 PHP WebSocket开发实例:如何实现特定功能的演示 Sep 12, 2023 am 08:29 AM

PHPWebSocket开发实例:如何实现特定功能的演示WebSocket是一种进行实时双向通信的协议,它使得在客户端和服务器之间建立持久的连接成为可能。对于需要实现实时功能或即时通信的Web应用程序来说,WebSocket是一种强大的工具。在本文中,我们将演示如何使用PHPWebSocket开发,并实现特定功能。准备环境在开始之前,确保你已经安装了PH

如何开发实现PHP WebSocket的功能? 如何开发实现PHP WebSocket的功能? Sep 12, 2023 am 11:13 AM

如何开发实现PHPWebSocket的功能?简介WebSocket是一种现代化的通信协议,它能够在客户端和服务器之间建立持久的、实时的双向通信连接。相比于传统的HTTP协议,WebSocket能够提供更低的延迟和更高的性能。本文将介绍如何使用PHP开发实现WebSocket的功能,让你能够在自己的应用中使用WebSocket来实现实时通信功能。确保服务器支

PHP WebSocket开发入门指南:实现弹幕功能的步骤解析 PHP WebSocket开发入门指南:实现弹幕功能的步骤解析 Sep 12, 2023 am 10:45 AM

PHPWebSocket开发入门指南:实现弹幕功能的步骤解析引言:随着互联网的发展,实时通信的需求也越来越迫切。WebSocket技术应运而生,为实现实时通信提供了便利。在本篇文章中,我们将通过PHP语言来实现一个简单的弹幕功能,帮助读者入门WebSocket开发,并了解实现实时通信的基本步骤。一、什么是WebSocket?WebSocket是一种在单个T

如何使用PHP WebSocket开发功能实现网页实时消息推送 如何使用PHP WebSocket开发功能实现网页实时消息推送 Sep 11, 2023 am 10:48 AM

如何使用PHPWebSocket开发功能实现网页实时消息推送随着互联网的快速发展,实时通信已经成为网页应用程序中不可或缺的一部分。在过去,网页与服务器之间的通信是通过客户端不断向服务器发送请求来实现的,这种方式效率较低,同时也给服务器带来了较大的压力。而使用WebSocket技术可以实现服务器主动向客户端推送消息,使得网页应用程序能够实时地接收和展示最新的

PHP WebSocket的开发指南:实现关键功能的步骤解析 PHP WebSocket的开发指南:实现关键功能的步骤解析 Sep 11, 2023 pm 07:25 PM

PHPWebSocket的开发指南:实现关键功能的步骤解析随着互联网应用的不断发展,WebSocket作为一种实时通信协议成为了Web开发中的重要工具。在PHP领域,通过使用WebSocket可以实现实时聊天、推送通知等功能。本文将详细介绍如何使用PHP开发WebSocket应用,并提供一些关键功能的步骤解析。一、WebSocket简介WebSocket是

PHP WebSocket开发功能详解:一步步实现你想要的效果 PHP WebSocket开发功能详解:一步步实现你想要的效果 Sep 11, 2023 pm 12:39 PM

PHPWebSocket是一项非常强大的技术,它使得实时通信成为可能。本文将详细介绍如何使用PHPWebSocket开发各种功能,一步步实现你想要的效果。WebSocket是一种在客户端和服务器之间建立持久连接的协议,它允许双向通信,并且能够实时传输数据。相较于传统的HTTP请求,WebSocket能够节省带宽和服务器资源,并且可以实时推送数据给客户端,

PHP WebSocket开发秘籍:打造功能强大且高度可定制的即时通信系统 PHP WebSocket开发秘籍:打造功能强大且高度可定制的即时通信系统 Sep 12, 2023 am 11:14 AM

PHPWebSocket开发秘籍:打造功能强大且高度可定制的即时通信系统引言:即时通信已经成为现代互联网生活中不可或缺的一部分。无论是在线聊天、实时通知,还是多人游戏,即时通信技术都扮演着重要角色。而基于Web的即时通信系统常常使用WebSocket协议来实现。本文将介绍如何使用PHP开发一个强大且高度可定制的即时通信系统。我们将涵盖WebSocket协议

如何在PHP中使用WebSocket? 如何在PHP中使用WebSocket? May 12, 2023 am 08:27 AM

随着Web应用程序越来越复杂,实时通信和数据推送变得越来越常见。这就是WebSocket的用武之地。WebSocket是一种协议,允许服务器和客户端建立双向通信的持久性连接,以便实时通信和数据推送。在本文中,我们将讨论如何在PHP中使用WebSocket。WebSocket协议简介WebSocket是一种全双工的、基于TCP的协议,它允许服务器和客户端在建立

See all articles