API Documentation
This commit is contained in:
parent
15ec375405
commit
c8a0911452
@ -11,6 +11,7 @@ use Ratchet\Command\Composite;
|
|||||||
*/
|
*/
|
||||||
class CloseConnection extends ActionTemplate {
|
class CloseConnection extends ActionTemplate {
|
||||||
function execute(SocketObserver $scope = null) {
|
function execute(SocketObserver $scope = null) {
|
||||||
|
// All this code allows an application to have its onClose method executed before the socket is actually closed
|
||||||
$ret = $scope->onClose($this->getSocket());
|
$ret = $scope->onClose($this->getSocket());
|
||||||
|
|
||||||
if ($ret instanceof CommandInterface) {
|
if ($ret instanceof CommandInterface) {
|
||||||
@ -21,7 +22,6 @@ class CloseConnection extends ActionTemplate {
|
|||||||
$rt->setCommand(function(SocketInterface $socket, SocketObserver $scope) {
|
$rt->setCommand(function(SocketInterface $socket, SocketObserver $scope) {
|
||||||
$socket->close();
|
$socket->close();
|
||||||
});
|
});
|
||||||
|
|
||||||
$comp->enqueue($rt);
|
$comp->enqueue($rt);
|
||||||
|
|
||||||
return $comp;
|
return $comp;
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
namespace Ratchet\Command;
|
namespace Ratchet\Command;
|
||||||
use Ratchet\SocketInterface;
|
use Ratchet\SocketInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single command tied to 1 socket connection
|
||||||
|
*/
|
||||||
interface ActionInterface extends CommandInterface {
|
interface ActionInterface extends CommandInterface {
|
||||||
/**
|
/**
|
||||||
* Pass the Sockets to execute the command on
|
* Pass the Sockets to execute the command on
|
||||||
|
@ -16,6 +16,7 @@ use Ratchet\Protocol\WebSocket\Util\HTTP;
|
|||||||
* @todo Make sure this works both ways (client/server) as stack needs to exist on client for framing
|
* @todo Make sure this works both ways (client/server) as stack needs to exist on client for framing
|
||||||
* @todo Learn about closing the socket. A message has to be sent prior to closing - does the message get sent onClose event or CloseConnection command?
|
* @todo Learn about closing the socket. A message has to be sent prior to closing - does the message get sent onClose event or CloseConnection command?
|
||||||
* @todo Consider cheating the application...don't call _app::onOpen until handshake is complete - only issue is sending headers/cookies
|
* @todo Consider cheating the application...don't call _app::onOpen until handshake is complete - only issue is sending headers/cookies
|
||||||
|
* @todo Consider chaning this class to a State Pattern. If a SocketObserver is passed in __construct, do what is there now. If it's an AppInterface change behaviour of socket interaction (onOpen, handshake, etc)
|
||||||
*/
|
*/
|
||||||
class WebSocket implements ProtocolInterface {
|
class WebSocket implements ProtocolInterface {
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +71,6 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
* @param int The port to listen to connections on
|
* @param int The port to listen to connections on
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @todo Validate address. Use socket_get_option, if AF_INET must be IP, if AF_UNIX must be path
|
* @todo Validate address. Use socket_get_option, if AF_INET must be IP, if AF_UNIX must be path
|
||||||
* @todo Should I make handling open/close/msg an application?
|
|
||||||
* @todo Consider making the 4kb listener changable
|
* @todo Consider making the 4kb listener changable
|
||||||
*/
|
*/
|
||||||
public function run($address = '127.0.0.1', $port = 1025) {
|
public function run($address = '127.0.0.1', $port = 1025) {
|
||||||
@ -139,9 +138,6 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
return $this->_app->onRecv($from, $msg);
|
return $this->_app->onRecv($from, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Make sure it's OK to executre the command after resources have been free'd
|
|
||||||
*/
|
|
||||||
public function onClose(SocketInterface $conn) {
|
public function onClose(SocketInterface $conn) {
|
||||||
$resource = $conn->getResource();
|
$resource = $conn->getResource();
|
||||||
|
|
||||||
|
@ -3,28 +3,29 @@ namespace Ratchet;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Observable/Observer design pattern interface for handing events on a socket
|
* Observable/Observer design pattern interface for handing events on a socket
|
||||||
|
* @todo Consider an onException method. Since server is running its own loop the app currently doesn't know when a problem is handled
|
||||||
|
* @todo Consider an onDisconnect method for a server-side close()'ing of a connection - onClose would be client side close()
|
||||||
*/
|
*/
|
||||||
interface SocketObserver {
|
interface SocketObserver {
|
||||||
/**
|
/**
|
||||||
* When a new connection is opened it will be passed to this method
|
* When a new connection is opened it will be passed to this method
|
||||||
* @param SocketInterface
|
* @param SocketInterface The socket/connection that just connected to your application
|
||||||
* @return Ratchet\Command\CommandInterface|null
|
* @return Ratchet\Command\CommandInterface|null
|
||||||
*/
|
*/
|
||||||
function onOpen(SocketInterface $conn);
|
function onOpen(SocketInterface $conn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered when a client sends data through the socket
|
* Triggered when a client sends data through the socket
|
||||||
* @param SocketInterface
|
* @param SocketInterface The socket/connection that sent the message to your application
|
||||||
* @param string
|
* @param string The message received
|
||||||
* @return Ratchet\Command\CommandInterface|null
|
* @return Ratchet\Command\CommandInterface|null
|
||||||
*/
|
*/
|
||||||
function onRecv(SocketInterface $from, $msg);
|
function onRecv(SocketInterface $from, $msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called just before the connection is closed
|
* This is called before or after a socket is closed (depends on how it's closed). SendMessage to $conn will not result in an error if it has already been closed.
|
||||||
* @param SocketInterface
|
* @param SocketInterface The socket/connection that is closing/closed
|
||||||
* @return Ratchet\Command\CommandInterface|null
|
* @return Ratchet\Command\CommandInterface|null
|
||||||
* @todo This is triggered if the client or server terminates the connection; consider a new onDisconnect if server triggered
|
|
||||||
*/
|
*/
|
||||||
function onClose(SocketInterface $conn);
|
function onClose(SocketInterface $conn);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user