Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Websocket\Server Class Reference
Inheritance diagram for Hoa\Websocket\Server:

Public Member Functions

 __construct (Socket\Server $server, Http\Request $request=null)
 
 setRequest (Http\Request $request)
 
 getRequest ()
 
- Public Member Functions inherited from Hoa\Websocket\Connection
 __construct (Socket\Connection $connection)
 
 on ($listenerId, $callable)
 
 send ($message, Socket\Node $node=null, $opcode=self::OPCODE_TEXT_FRAME, $end=true)
 
 close ($code=self::CLOSE_NORMAL, $reason=null)
 
- Public Member Functions inherited from Hoa\Socket\Connection\Handler
 __construct (Connection $connection)
 
 getConnection ()
 
 run ()
 
 merge (self $other)
 
 send ($message, Socket\Node $node=null)
 
 broadcast ($message)
 
 broadcastIf (\Closure $predicate, $message)
 

Protected Member Functions

 doHandshake ()
 
- Protected Member Functions inherited from Hoa\Websocket\Connection
 _run (Socket\Node $node)
 
 doHandshake ()
 
 _send ($message, Socket\Node $node)
 
- Protected Member Functions inherited from Hoa\Socket\Connection\Handler
 setConnection (Connection $connection)
 
 getOriginalConnection ()
 
 _run (Socket\Node $node)
 
 _send ($message, Socket\Node $node)
 

Protected Attributes

 $_request = null
 
- Protected Attributes inherited from Hoa\Websocket\Connection
 $_on = null
 
- Protected Attributes inherited from Hoa\Socket\Connection\Handler
 $_originalConnection = null
 
 $_connection = null
 
 $_connections = []
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Websocket\Connection
const OPCODE_CONTINUATION_FRAME = 0x0
 
const OPCODE_TEXT_FRAME = 0x1
 
const OPCODE_BINARY_FRAME = 0x2
 
const OPCODE_CONNECTION_CLOSE = 0x8
 
const OPCODE_PING = 0x9
 
const OPCODE_PONG = 0xa
 
const CLOSE_NORMAL = 1000
 
const CLOSE_GOING_AWAY = 1001
 
const CLOSE_PROTOCOL_ERROR = 1002
 
const CLOSE_DATA_ERROR = 1003
 
const CLOSE_STATUS_ERROR = 1005
 
const CLOSE_ABNORMAL = 1006
 
const CLOSE_MESSAGE_ERROR = 1007
 
const CLOSE_POLICY_ERROR = 1008
 
const CLOSE_MESSAGE_TOO_BIG = 1009
 
const CLOSE_EXTENSION_MISSING = 1010
 
const CLOSE_SERVER_ERROR = 1011
 
const CLOSE_TLS = 1015
 

Detailed Description

Class .

A cross-protocol Websocket server.

Definition at line 50 of file Server.php.

Constructor & Destructor Documentation

Hoa\Websocket\Server::__construct ( Socket\Server  $server,
Http\Request  $request = null 
)

Create a Websocket server.

Parameters
\Hoa\Socket\Server$serverServer.
\Hoa\Http\Request$requestRequest parser.
Returns
void
Exceptions

Definition at line 69 of file Server.php.

72  {
73  parent::__construct($server);
74 
75  if (null === $request) {
76  $request = new Http\Request();
77  }
78 
79  $this->setRequest($request);
80 
81  return;
82  }
setRequest(Http\Request $request)
Definition: Server.php:127

Here is the call graph for this function:

Member Function Documentation

Hoa\Websocket\Server::doHandshake ( )
protected

Try the handshake by trying different protocol implementation.

Returns
void
Exceptions

Definition at line 90 of file Server.php.

91  {
92  $connection = $this->getConnection();
93  $buffer = $connection->read(2048);
94  $request = $this->getRequest();
95  $request->parse($buffer);
96 
97  // Rfc6455.
98  try {
99  $rfc6455 = new Protocol\Rfc6455($connection);
100  $rfc6455->doHandshake($request);
101  $connection->getCurrentNode()->setProtocolImplementation($rfc6455);
102  } catch (Exception\BadProtocol $e) {
103  unset($rfc6455);
104 
105  // Hybi00.
106  try {
107  $hybi00 = new Protocol\Hybi00($connection);
108  $hybi00->doHandshake($request);
109  $connection->getCurrentNode()->setProtocolImplementation($hybi00);
110  } catch (Exception\BadProtocol $e) {
111  unset($hybi00);
112  $connection->disconnect();
113 
114  throw new Exception\BadProtocol('All protocol failed.', 1);
115  }
116  }
117 
118  return;
119  }

Here is the call graph for this function:

Hoa\Websocket\Server::getRequest ( )

Get request.

Returns

Definition at line 140 of file Server.php.

141  {
142  return $this->_request;
143  }

Here is the caller graph for this function:

Hoa\Websocket\Server::setRequest ( Http\Request  $request)

Set request (mainly parser).

Parameters
\Hoa\Http\Request$requestRequest.
Returns

Definition at line 127 of file Server.php.

128  {
129  $old = $this->_request;
130  $this->_request = $request;
131 
132  return $old;
133  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Websocket\Server::$_request = null
protected

Definition at line 57 of file Server.php.


The documentation for this class was generated from the following file: