首頁 後端開發 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脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
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)

熱門話題

Java教學
1664
14
CakePHP 教程
1423
52
Laravel 教程
1321
25
PHP教程
1269
29
C# 教程
1249
24
PHP WebSocket開發實例:如何實作特定功能的示範 PHP WebSocket開發實例:如何實作特定功能的示範 Sep 12, 2023 am 08:29 AM

PHPWebSocket開發實例:如何實現特定功能的演示WebSocket是一種進行即時雙向通訊的協議,它使得在客戶端和伺服器之間建立持久的連接成為可能。對於需要實現即時功能或即時通訊的網路應用程式來說,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 12, 2023 am 11:14 AM

PHPWebSocket開發秘技:打造功能強大且高度可自訂的即時通訊系統引言:即時通訊已成為現代網路生活中不可或缺的一部分。無論是在線上聊天、即時通知,還是多人遊戲,即時通訊技術都扮演著重要角色。而基於Web的即時通訊系統常常使用WebSocket協定來實現。本文將介紹如何使用PHP開發一個強大且高度可自訂的即時通訊系統。我們將涵蓋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 08:25 AM

PHPWebSocket開發:掌握實現功能時的效能調優與最佳化技巧在現代Web應用中,即時通訊成為了越來越重要的功能需求。 WebSocket作為一種能夠實現雙向通訊的協議,被廣泛應用於聊天應用、即時推送等場景中。而PHP作為一種流行的後端開發語言,也提供了WebSocket的支援。在實現WebSocket功能時,效能調優和最佳化技巧是至關重要的,本文將介紹一些

See all articles