PHP Interface Aerys\Websocket

ファイルを表示 Open project: amphp/aerys

Public Methods

Method Description
onClose ( integer $clientId, integer $code, string $reason ) Invoked when the close handshake completes
onData ( integer $clientId, Websocket\Message $msg ) Invoked when data messages arrive from the client
onHandshake ( aerys\Request $request, aerys\Response $response ) Respond to websocket handshake requests
onOpen ( integer $clientId, mixed $handshakeData ) Invoked when the full two-way websocket upgrade completes
onStart ( Aerys\Websocket\Endpoint $endpoint ) Invoked when starting the server
onStop ( ) Invoked when the server is stopping

Method Details

onClose() public method

Invoked when the close handshake completes
public onClose ( integer $clientId, integer $code, string $reason )
$clientId integer A unique (to the current process) identifier for this client
$code integer The websocket code describing the close
$reason string The reason for the close (may be empty)

onData() public method

Invoked when data messages arrive from the client
public onData ( integer $clientId, Websocket\Message $msg )
$clientId integer A unique (to the current process) identifier for this client
$msg Websocket\Message A stream of data received from the client

onHandshake() public method

If a websocket application doesn't wish to impose any special constraints on the handshake it doesn't have to do anything in this method and all handshakes will be automatically accepted. The return value from onHandshake() invocation (which may be the eventual generator return expression) is passed as the second parameter to onOpen().
public onHandshake ( aerys\Request $request, aerys\Response $response )
$request aerys\Request The HTTP request that instigated the handshake
$response aerys\Response Used to set headers and/or reject the handshake

onOpen() public method

Invoked when the full two-way websocket upgrade completes
public onOpen ( integer $clientId, mixed $handshakeData )
$clientId integer A unique (to the current process) identifier for this client
$handshakeData mixed The return value from onHandshake() for this client

onStart() public method

All messages are sent to connected clients by calling methods on the Endpoint instance passed in onStart(). Applications must store the endpoint instance for use once the server starts. If the websocket application has external resources it needs to initialize (like database connections) this is the place to do it. If this method is a Generator it will be resolved as a coroutine before the server is allowed to start. Additionally, this method returns a Promise the server will not start until that promise resolves.
public onStart ( Aerys\Websocket\Endpoint $endpoint )
$endpoint Aerys\Websocket\Endpoint

onStop() public method

If the application initialized resources in Websocket::onStart() this is the place to free them. This method is called right before the clients will be all automatically closed. There is no need to call Endpoint::close() manually in this method. If this method is a Generator it will be resolved as a coroutine before the server is allowed to fully shutdown. Additionally, if this method returns a Promise the server will not shutdown until that promise resolves.
public onStop ( )