WAMP Interface

Updated interfaces from app refactor to branch out WAMP on top of WebSocket app
This commit is contained in:
Chris Boden 2012-01-08 22:15:31 -05:00
parent 5334f94b91
commit 3a4bdc918c
3 changed files with 10 additions and 10 deletions

View File

@ -80,6 +80,7 @@ class App implements ApplicationInterface {
declare(ticks = 1); declare(ticks = 1);
$host->set_option(SOL_SOCKET, SO_SNDBUF, $this->_buffer_size);
$host->set_nonblock()->bind($address, (int)$port)->listen(); $host->set_nonblock()->bind($address, (int)$port)->listen();
do { do {
@ -105,7 +106,7 @@ class App implements ApplicationInterface {
$res = $this->onOpen($conn); $res = $this->onOpen($conn);
} else { } else {
$data = $buf = ''; $data = $buf = '';
$bytes = $conn->getSocket()->recv($buf, $this->_buffer_size, 0); $bytes = $conn->getSocket()->recv($buf, $this->_buffer_size, MSG_DONTWAIT);
if ($bytes > 0) { if ($bytes > 0) {
$data = $buf; $data = $buf;

View File

@ -21,16 +21,15 @@ use Ratchet\Resource\Connection;
* @link http://www.tavendo.de/autobahn/protocol.html * @link http://www.tavendo.de/autobahn/protocol.html
* @todo I can't make up my mind what interface to present to the server application * @todo I can't make up my mind what interface to present to the server application
*/ */
class App implements ApplicationInterface, WebSocketAppInterface { class App implements WebSocketAppInterface {
protected $_app;
protected static $_incoming = array(1, 2, 5, 6, 7); protected static $_incoming = array(1, 2, 5, 6, 7);
public function getSubProtocol() { public function getSubProtocol() {
return 'wamp'; return 'wamp';
} }
public function attachHandler(ServerInterface $app) {
}
/** /**
* @todo WAMP spec does not say what to do when there is an error with PREFIX... * @todo WAMP spec does not say what to do when there is an error with PREFIX...
*/ */
@ -72,12 +71,12 @@ class App implements ApplicationInterface, WebSocketAppInterface {
if ($json[0] == 1) { if ($json[0] == 1) {
$this->addPrefix($conn, $json[2], $json[1]); $this->addPrefix($conn, $json[2], $json[1]);
} }
// Determine WAMP message type, call $_this->_app->on();
} }
public function __construct(ApplicationInterface $app = null) { public function __construct(ServerInterface $app) {
if (null !== $app) { $this->_app = $app;
throw new \InvalidArgumentException('WAMP is the end of the Socket stack, apps build on this must conform to the WAMP protocol');
}
} }
public function onClose(Connection $conn) { public function onClose(Connection $conn) {

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Ratchet\Application\WAMP; namespace Ratchet\Application\WAMP;
class JSONException extends \Exception { class JSONException extends Exception {
public function __construct() { public function __construct() {
$code = json_last_error(); $code = json_last_error();