Skip to content

Commit b0db0ee

Browse files
committed
Updated README.md
1 parent cf46e47 commit b0db0ee

File tree

2 files changed

+83
-47
lines changed

2 files changed

+83
-47
lines changed

README.md

+82-46
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
Description
2-
===========
3-
41
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.
52

63
This project was started to bring more interactive features to http://www.u2start.com/
74

8-
Downloads
9-
---------
10-
The current version available for download is 1.0 RC1. This version has been thouroughly tested. However documentation is still minimal.
11-
125
Features
13-
---------
6+
============
147
Server
158
* Hixie #76 and Hybi #12 protocol versions
169
* Flash client support (also serves XML policy file on the same port)
@@ -20,38 +13,32 @@ Server
2013

2114
Client
2215
* Hybi / Hixie76 support.
16+
* Event-based Async I/O
17+
18+
19+
Getting started
20+
=================
21+
The easiest way to set up PHPWS is by using it as Composer dependency. Add the following to your composer.json
22+
23+
```json
24+
{
25+
"repositories": [
26+
{
27+
"type": "vcs",
28+
"url": "https://github.com/Devristo/phpws"
29+
}
30+
],
31+
"require": {
32+
"devristo/phpws": "dev-react"
33+
}
34+
}
35+
```
2336

37+
And run ```php composer.phar install```
2438

25-
Known Issues
26-
-------------
27-
* Lacks ORIGIN checking (can be implemented manually in onConnect using getHeaders(), just disconnect the user when you dont like the Origin header)
28-
* No support for extension data from the HyBi specs.
29-
30-
Requirements
31-
-------------
32-
*Server*
33-
* PHP 5.3
34-
* Open port for the server
35-
* PHP OpenSSL module to run a server over a encrypted connection
36-
37-
* Composer dependencies *
38-
These will be installed automatically when using phpws as a composer package.
39-
40-
* Reactphp
41-
* ZF2 Logger
42-
43-
*Client*
44-
* PHP 5.3
45-
* Server that implements the HyBi (#8-#12) draft version
46-
* PHP OpenSSL module to connect using SSL (wss:// uris)
47-
48-
Server Example
49-
---------------
50-
```php
51-
require_once("vendor/autoload.php"); // Composer autoloader
52-
53-
use Devristo\Phpws\Messaging\WebSocketMessageInterface;
54-
use Devristo\Phpws\Protocol\WebSocketConnectionInterface;
39+
To verify it is working create a time.php in your project root
40+
```
41+
require_once("vendor/autoload.php");
5542
use Devristo\Phpws\Server\WebSocketServer;
5643
5744
$loop = \React\EventLoop\Factory::create();
@@ -64,14 +51,14 @@ $logger->addWriter($writer);
6451
// Create a WebSocket server using SSL
6552
$server = new WebSocketServer("tcp://0.0.0.0:12345", $loop, $logger);
6653
67-
$server->on("connect", function(WebSocketConnectionInterface $user){
68-
$user->sendString("Hey! I am the echo robot. I will repeat all your input!");
54+
$loop->addPeriodicTimer(0.5, function() use($server, $logger){
55+
$time = new DateTime();
56+
$string = $time->format("Y-m-d H:i:s");
57+
$logger->notice("Broadcasting time to all clients: $string");
58+
foreach($server->getConnections() as $client)
59+
$client->sendString($string);
6960
});
7061
71-
$server->on("message", function(WebSocketConnectionInterface $user, WebSocketMessageInterface $message) use($logger){
72-
$logger->notice(sprintf("We have got '%s' from client %s", $message->getData(), $user->getId()));
73-
$user->sendString($message->getData());
74-
});
7562
7663
// Bind the server
7764
$server->bind();
@@ -80,8 +67,32 @@ $server->bind();
8067
$loop->run();
8168
```
8269

83-
Client Example
84-
---------------------
70+
And a client time.html as follows
71+
```html
72+
<html>
73+
<head>
74+
<title>WebSocket TEST</title>
75+
</head>
76+
<body>
77+
<h1>Server Time</h1>
78+
<strong id="time"></strong>
79+
80+
<script>
81+
var socket = new WebSocket("ws://localhost:12345/");
82+
socket.onmessage = function(msg) {
83+
document.getElementById("time").innerText = msg.data;
84+
};
85+
</script>
86+
</body>
87+
</html>
88+
```
89+
Now run the time.php from the command line and open time.html in your browser. You should see the current time, broadcasted
90+
by phpws at regular intervals. If this works you might be interested in more complicated servers in the examples folder.
91+
92+
Getting started with the Phpws Client
93+
=======================================
94+
The following is a client for the websocket server hosted at http://echo.websocket.org
95+
8596
```php
8697
require_once("vendor/autoload.php"); // Composer autoloader
8798

@@ -106,3 +117,28 @@ $client->on("message", function($message) use ($client, $logger){
106117
$client->open();
107118
$loop->run();
108119
```
120+
121+
122+
Known Issues
123+
==================
124+
* Lacks ORIGIN checking (can be implemented manually in onConnect using getHeaders(), just disconnect the user when you dont like the Origin header)
125+
* No support for extension data from the HyBi specs.
126+
127+
Requirements
128+
=================
129+
*Server*
130+
* PHP 5.3
131+
* Open port for the server
132+
* PHP OpenSSL module to run a server over a encrypted connection
133+
134+
* Composer dependencies *
135+
These will be installed automatically when using phpws as a composer package.
136+
137+
* Reactphp
138+
* ZF2 Logger
139+
140+
*Client*
141+
* PHP 5.3
142+
* Server that implements the HyBi (#8-#12) draft version
143+
* PHP OpenSSL module to connect using SSL (wss:// uris)
144+

tests/framing.test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function test_maskedTextMessage() {
4747
}
4848

4949
/**
50-
* @expectedException WebSocketMessageNotFinalised
50+
* @expectedException \Devristo\Phpws\Exceptions\WebSocketMessageNotFinalised
5151
*/
5252
function test_incompleteTextMessage() {
5353
$bf1 = "\x01\x03\x48\x65\x6c";

0 commit comments

Comments
 (0)