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();
Copy after login
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
Copy after login

?> 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP WebSocket development example: demonstration of how to implement specific functions PHP WebSocket development example: demonstration of how to implement specific functions Sep 12, 2023 am 08:29 AM

PHP WebSocket development example: Demonstration of how to implement specific functions WebSocket is a protocol for real-time two-way communication, which makes it possible to establish a persistent connection between the client and the server. WebSocket is a powerful tool for web applications that need to implement real-time functionality or instant communication. In this article, we will demonstrate how to develop using PHPWebSocket and implement specific functions. Preparing the environment Before starting, make sure you have PH installed

Getting Started Guide to PHP WebSocket Development: Analysis of Steps to Implement the Barrage Function Getting Started Guide to PHP WebSocket Development: Analysis of Steps to Implement the Barrage Function Sep 12, 2023 am 10:45 AM

Getting Started Guide to PHP WebSocket Development: Analysis of Steps to Implement the Barrage Function Introduction: With the development of the Internet, the need for real-time communication is becoming more and more urgent. WebSocket technology emerged as the times require, providing convenience for real-time communication. In this article, we will use PHP language to implement a simple barrage function to help readers get started with WebSocket development and understand the basic steps to achieve real-time communication. 1. What is WebSocket? WebSocket is a method in a single T

How to develop and implement PHP WebSocket functions? How to develop and implement PHP WebSocket functions? Sep 12, 2023 am 11:13 AM

How to develop and implement the functions of PHPWebSocket? Introduction WebSocket is a modern communication protocol that enables the establishment of persistent, real-time, two-way communication connections between clients and servers. Compared with the traditional HTTP protocol, WebSocket can provide lower latency and higher performance. This article will introduce how to use PHP to develop and implement WebSocket functions, so that you can use WebSocket to implement real-time communication functions in your own applications. Make sure the server supports

How to use PHP WebSocket development function to implement real-time message push on web pages How to use PHP WebSocket development function to implement real-time message push on web pages Sep 11, 2023 am 10:48 AM

How to use the PHP WebSocket development function to implement real-time message push on web pages. With the rapid development of the Internet, real-time communication has become an indispensable part of web applications. In the past, communication between web pages and servers was achieved by the client continuously sending requests to the server. This method was inefficient and also put greater pressure on the server. Using WebSocket technology, the server can actively push messages to the client, allowing web applications to receive and display the latest information in real time.

PHP WebSocket Development Guide: Analysis of Steps to Implement Key Functions PHP WebSocket Development Guide: Analysis of Steps to Implement Key Functions Sep 11, 2023 pm 07:25 PM

PHP WebSocket Development Guide: Analysis of Steps to Implement Key Functions With the continuous development of Internet applications, WebSocket, as a real-time communication protocol, has become an important tool in Web development. In the field of PHP, real-time chat, push notifications and other functions can be realized by using WebSocket. This article will introduce in detail how to use PHP to develop WebSocket applications and provide step-by-step analysis of some key functions. 1. Introduction to WebSocket WebSocket is

Detailed explanation of PHP WebSocket development functions: step by step to achieve the effect you want Detailed explanation of PHP WebSocket development functions: step by step to achieve the effect you want Sep 11, 2023 pm 12:39 PM

PHPWebSocket is a very powerful technology that makes real-time communication possible. This article will introduce in detail how to use PHPWebSocket to develop various functions and achieve the results you want step by step. WebSocket is a protocol that establishes a persistent connection between a client and a server, allowing two-way communication and the ability to transmit data in real time. Compared with traditional HTTP requests, WebSocket can save bandwidth and server resources, and can push data to the client in real time.

PHP WebSocket Development Tips: Create a powerful and highly customizable instant messaging system PHP WebSocket Development Tips: Create a powerful and highly customizable instant messaging system Sep 12, 2023 am 11:14 AM

PHPWebSocket development tips: Create a powerful and highly customizable instant messaging system Introduction: Instant messaging has become an indispensable part of modern Internet life. Whether it's online chat, real-time notifications, or multiplayer gaming, instant messaging technology plays an important role. Web-based instant messaging systems are often implemented using the WebSocket protocol. This article will introduce how to use PHP to develop a powerful and highly customizable instant messaging system. We will cover the WebSocket protocol

How to use WebSocket in PHP? How to use WebSocket in PHP? May 12, 2023 am 08:27 AM

As web applications become more complex, real-time communication and data push are becoming more common. This is where WebSocket comes in. WebSocket is a protocol that allows servers and clients to establish persistent connections for two-way communication for real-time communication and data push. In this article, we will discuss how to use WebSocket in PHP. Introduction to the WebSocket protocol WebSocket is a full-duplex, TCP-based protocol that allows the server and client to establish

See all articles