Skip to content

Commit

Permalink
FF now using websocket object. Some changes in php-client. Minor
Browse files Browse the repository at this point in the history
bugfixes/improvements.
  • Loading branch information
nekudo committed Apr 7, 2012
1 parent f4109c2 commit 89d0825
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 327 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ PHP WebSocket
=============
A websocket server implemented in php.

- Supports websocket draft hybi-10,13 (Currently tested with Chrome 16 and Firefox 9).
- Supports websocket draft hybi-10,13 (Currently tested with Chrome 18 and Firefox 11).
- Supports origin-check.
- Supports various security/performance settings.
- Supports binary frames. (Currently receive only)
- Supports wss (Very Alpha! Chrome only!)
- Supports wss. (Needs valid certificate in Firefox.)
- Application module, the server can be extended by custom behaviors.

## Bugs/Todos/Hints
- Optimize whole WSS/TLS stuff
- Optimize readBuffer() method. (Ideas welcome!)
- Add support for fragmented frames.

## Server example
Expand All @@ -23,9 +21,9 @@ This creates a server on localhost:8000 with one Application that listens on `ws
// server settings:
$server->setCheckOrigin(true);
$server->setAllowedOrigin('foo.lh');
$server->setMaxClients(20);
$server->setMaxConnectionsPerIp(5);
$server->setMaxRequestsPerMinute(50);
$server->setMaxClients(100);
$server->setMaxConnectionsPerIp(20);
$server->setMaxRequestsPerMinute(1000);

$server->registerApplication('demo', \WebSocket\Application\DemoApplication::getInstance());
$server->run();
Expand All @@ -34,4 +32,8 @@ This creates a server on localhost:8000 with one Application that listens on `ws

- [SplClassLoader](http://gist.github.com/221634) by the PHP Standards Working Group
- [jQuery](http://jquery.com/)
- [CoffeeScript PHP] (https://github.com/alxlit/coffeescript-php)
- [CoffeeScript PHP] (https://github.com/alxlit/coffeescript-php)

## Demo

- Check out http://jitt.li for a sample-project using this websocket server.
251 changes: 0 additions & 251 deletions client/client.php

This file was deleted.

8 changes: 4 additions & 4 deletions client/coffee/client.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
$(document).ready ->
log = (msg) -> $('#log').append("#{msg}<br />")
serverUrl = 'ws://127.0.0.1:8000/demo'
if $.browser.mozilla
socket = new MozWebSocket(serverUrl)
else
socket = new WebSocket(serverUrl)
if window.MozWebSocket
socket = new MozWebSocket serverUrl
else if window.WebSocket
socket = new WebSocket serverUrl
socket.binaryType = 'blob'

socket.onopen = (msg) ->
Expand Down
8 changes: 4 additions & 4 deletions client/coffee/status.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
$(document).ready ->
log = (msg) -> $('#log').prepend("#{msg}<br />")
serverUrl = 'ws://localhost:8000/status'
if $.browser.mozilla
socket = new MozWebSocket(serverUrl)
else
socket = new WebSocket(serverUrl)
if window.MozWebSocket
socket = new MozWebSocket serverUrl
else if window.WebSocket
socket = new WebSocket serverUrl

socket.onopen = (msg) ->
$('#status').removeClass().addClass('online').html('connected')
Expand Down
14 changes: 9 additions & 5 deletions server/lib/WebSocket/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function run()
while(true)
{
$changed_sockets = $this->allsockets;
@stream_select($changed_sockets, $write = null, $except = null, 0, 5000);
@stream_select($changed_sockets, $write = null, $except = null, 0, 5000);
foreach($changed_sockets as $socket)
{
if($socket == $this->master)
Expand Down Expand Up @@ -74,15 +74,19 @@ public function run()
}
}
else
{
$client = $this->clients[(int)$socket];
{
$client = $this->clients[(int)$socket];
if(!is_object($client))
{
unset($this->clients[(int)$socket]);
continue;
}
$data = $this->readBuffer($socket);
$bytes = strlen($data);

if($bytes === 0)
{
$client->onDisconnect();
//$this->removeClientOnError($client);
$client->onDisconnect();
continue;
}
elseif($data === false)
Expand Down
Loading

0 comments on commit 89d0825

Please sign in to comment.