WebSocketBase

Base WebSocket implementation.

It implements both and so it can be used with

see

to pump data with flow control.

package

Default

Methods

__construct

__construct() 

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\WebSocketBase::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

Set a close handler. This will be called when the WebSocket is closed.

closeHandler( $arg0) : $this

After this callback, no more messages are expected.

Arguments

$arg0

callable

Response

$this

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

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

Set a frame handler on the connection. This handler will be called when frames are read on the connection.

frameHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

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

handler

handler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

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

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

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

write

write( $arg0) : $this

Arguments

$arg0

Buffer

Response

$this

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

writeBinaryMessage( $arg0) : $this

Arguments

$arg0

Buffer

Response

$this

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

Write a final WebSocket binary frame to the connection

writeFinalBinaryFrame( $arg0) : $this

Arguments

$arg0

Buffer

Response

$this

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

Write a final WebSocket text frame to the connection

writeFinalTextFrame( $arg0) : $this

Arguments

$arg0

string

Response

$this

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

Write a WebSocket frame to the connection

writeFrame( $arg0) : $this

Arguments

$arg0

WebSocketFrame

Response

$this

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

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\WebSocketBase::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