ServerWebSocket

Represents a server side WebSocket.

Instances of this class are passed into a @see \io\vertx\jphp\core\http\HttpServer::websocketHandler or provided when a WebSocket handshake is manually @see \io\vertx\jphp\core\http\HttpServerRequest::upgradeed.

package

Default

Methods

__construct

__construct() 

Accept the WebSocket and terminate the WebSocket handshake.

accept() : void

This method should be called from the websocket handler to explicitely accept the websocker and terminate the WebSocket handshake.

When a <code>Websocket</code> is created it automatically registers an event handler with the event bus - the ID of that handler is given by this method.

binaryHandlerID() : string

Given this ID, a different event loop can send a binary frame to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other WebSockets which are owned by different event loops.

Response

string

the binary handler id

Set a binary message handler on the connection. This handler serves a similar purpose to @see \io\vertx\jphp\core\http\ServerWebSocket::handler except that if a message comes into the socket in multiple frames, the data from the frames will be aggregated into a single buffer before calling the handler (using @see \io\vertx\jphp\core\http\WebSocketFrame::isFinal to find the boundaries).

binaryMessageHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Close the WebSocket sending the default close frame.

close( $arg0 = null,  $arg1 = null) : void

No more messages can be sent.

close()

param $statusCode [integer] close($statusCode)

param $statusCode [integer] param $reason [string] close($statusCode, $reason)

Arguments

$arg0

integer

$arg1

string

closeHandler

closeHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

drainHandler

drainHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

Calls @see \io\vertx\jphp\core\http\WebSocketBase::close

end( $arg0 = null) : void

end()

Same as @see \io\vertx\jphp\core\http\WebSocketBase::end but writes some data to the stream before ending.

param $t [Buffer] end($t)

Arguments

$arg0

Buffer

endHandler

endHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

exceptionHandler

exceptionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

fetch

fetch( $arg0) : $this

Arguments

$arg0

integer

Response

$this

frameHandler

frameHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

handler

handler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

headers

headers() : \io\vertx\jphp\core\MultiMap

Response

\io\vertx\jphp\core\MultiMap

the headers in the WebSocket handshake

isSsl

isSsl() : boolean

Response

boolean

true if this {@link io.vertx.core.http.HttpConnection} is encrypted via SSL/TLS.

localAddress

localAddress() : \io\vertx\jphp\core\net\SocketAddress

Response

\io\vertx\jphp\core\net\SocketAddress

the local address for this socket

path

path() : string

Response

string

the WebSocket handshake path.

pause

pause() : $this

Response

$this

Set a pong message handler on the connection. This handler will be invoked every time a pong message is received on the server, and can be used by both clients and servers since the RFC 6455 Sections 5.5.2 and 5.5.3 do not specify whether the client or server sends a ping.

pongHandler( $arg0) : $this

Pong frames may be at most 125 bytes (octets).

There is no ping handler since pings should immediately be responded to with a pong with identical content

Pong frames may be received unsolicited.

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

query

query() : string

Response

string

the WebSocket handshake query string.

Reject the WebSocket.

reject( $arg0 = null) : void

Calling this method from the websocket handler when it is first passed to you gives you the opportunity to reject the websocket, which will cause the websocket handshake to fail by returning a response code.

You might use this method, if for example you only want to accept WebSockets with a particular path. reject() Like @see \io\vertx\jphp\core\http\ServerWebSocket::reject but with a status. param $status [integer] reject($status)

Arguments

$arg0

integer

remoteAddress

remoteAddress() : \io\vertx\jphp\core\net\SocketAddress

Response

\io\vertx\jphp\core\net\SocketAddress

the remote address for this socket

resume

resume() : $this

Response

$this

setWriteQueueMaxSize

setWriteQueueMaxSize( $arg0) : $this

Arguments

$arg0

integer

Response

$this

Returns the websocket sub protocol selected by the websocket handshake.

subProtocol() : string

On the server, the value will be null when the handler receives the websocket callback as the handshake will not be completed yet.

Response

string

When a <code>Websocket</code> is created it automatically registers an event handler with the eventbus, the ID of that handler is given by <code>textHandlerID</code>.

textHandlerID() : string

Given this ID, a different event loop can send a text frame to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other WebSockets which are owned by different event loops.

Response

string

Set a text message handler on the connection. This handler will be called similar to the , but the buffer will be converted to a String first

textMessageHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

uri

uri() : string

Response

string

write

write( $arg0) : $this

Arguments

$arg0

Buffer

Response

$this

writeBinaryMessage

writeBinaryMessage( $arg0) : $this

Arguments

$arg0

Buffer

Response

$this

writeFinalBinaryFrame

writeFinalBinaryFrame( $arg0) : $this

Arguments

$arg0

Buffer

Response

$this

writeFinalTextFrame

writeFinalTextFrame( $arg0) : $this

Arguments

$arg0

string

Response

$this

writeFrame

writeFrame( $arg0) : $this

Arguments

$arg0

WebSocketFrame

Response

$this

Writes a ping to the connection. This will be written in a single frame. Ping frames may be at most 125 bytes (octets).

writePing( $arg0) : $this

This method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section 5.5.2.

There is no pingHandler because RFC 6455 section 5.5.2 clearly states that the only response to a ping is a pong with identical contents.

Arguments

$arg0

Buffer

Response

$this

a reference to this, so the API can be used fluently

Writes a pong to the connection. This will be written in a single frame. Pong frames may be at most 125 bytes (octets).

writePong( $arg0) : $this

This method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section 5.5.2.

There is no need to manually write a Pong, as the server and client both handle responding to a ping with a pong automatically and this is exposed to users.RFC 6455 Section 5.5.3 states that pongs may be sent unsolicited in order to implement a one way heartbeat.

Arguments

$arg0

Buffer

Response

$this

a reference to this, so the API can be used fluently

This will return <code>true</code> if there are more bytes in the write queue than the value set using @see \io\vertx\jphp\core\http\ServerWebSocket::setWriteQueueMaxSize

writeQueueFull() : boolean

Response

boolean

true if write queue is full

Writes a (potentially large) piece of text data to the connection. This data might be written as multiple frames if it exceeds the maximum WebSocket frame size.

writeTextMessage( $arg0) : $this

Arguments

$arg0

string

Response

$this

a reference to this, so the API can be used fluently