WebSocketServer
+ Inheritance diagram for WebSocketServer:

Description

A WebSocket server.

See also
https://tools.ietf.org/html/rfc6455

Protected Properties

WebSocketClient[] $clients = []
 Holds all connected clients. More...
 
Reactor $reactor
 
- Protected Properties inherited from AbstractSocket
resource $resource
 The underlying PHP resource. More...
 

Public Methods

 __construct ($resource, Reactor $reactor)
 
WebSocketClient accept ()
 
 broadcast (int $opCode, string $payload)
 Sends a payload to all clients in the OK state. More...
 
 broadcastBinary (string $payload)
 
 broadcastPing (string $payload='')
 Sends a ping to all clients in the OK state. More...
 
 broadcastText (string $text)
 Sends a message to all clients in the OK state. More...
 
$this close (int $code=Frame::CLOSE_INTERRUPT, $reason='')
 Closes and removes all clients. More...
 
int count ()
 The number of clients attached. More...
 
WebSocketClient[] getClients ()
 
void onOutOfBand ()
 WebSocket servers never get OOB data. More...
 
void onReadable ()
 Auto-accept. More...
 
void remove ($client)
 Removes the client from the server and reactor. More...
 
- Public Methods inherited from StreamServer
$this listen (int $backlog=0)
 Enables incoming connections. More...
 
- Public Methods inherited from AbstractServer
string __toString ()
 The server's name as <address>:<port>, or <filepath>:0 for Unix sockets, or ?<id> if a name can't be derived (e.g. More...
 
$this bind (string $address, int $port=0)
 Binds to an address and port, or file path (Unix) for the OS to create, so the server can listen. More...
 
- Public Methods inherited from AbstractSocket
 __construct ($resource)
 Validates and sets the underlying socket resource. More...
 
 __destruct ()
 Closes the socket if it's open. More...
 
$this await (int $channel)
 Blocks until the socket becomes available on a given channel. More...
 
$this awaitOutOfBand ()
 
$this awaitReadable ()
 
$this awaitWritable ()
 
$this close ()
 Closes the underlying resource if it's open. More...
 
int getDomain ()
 The AF_* address family constant. More...
 
int getId ()
 
mixed getOption (int $option)
 Retrieves an option value. More...
 
resource getResource ()
 
array getSockName ()
 The local address and port, or Unix file path and port 0. More...
 
bool isOpen ()
 
bool isOutOfBand ()
 Polls for whether the socket can perform a non-blocking out-of-band read. More...
 
bool isReadable ()
 Polls for whether the socket can perform a non-blocking read. More...
 
bool isReady (int $channel, ?float $timeout=0)
 Selects for channel availability. More...
 
bool isWritable ()
 Polls for whether the socket can perform a non-blocking write. More...
 
$this setBlocking (bool $blocking)
 Enables or disables blocking. More...
 
$this setOption (int $option, $value)
 Sets an option on the underlying resource. More...
 
$this setTimeout (float $timeout)
 Sets the I/O timeout length in seconds. More...
 
$this shutdown (int $channel)
 Shuts down I/O for a single channel. More...
 

Protected Methods

WebSocketClient newClient ($resource)
 

Additional Inherited Members

- Public Properties inherited from SocketInterface
const CH_EXCEPT = 2
 Out-of-band channel. More...
 
const CH_READ = 0
 Read channel. More...
 
const CH_WRITE = 1
 Write channel. More...
 
- Public Static Methods inherited from StreamServer
static int getType ()
 SOCK_STREAM More...
 
- Public Static Methods inherited from AbstractSocket
static self create (int $domain=AF_INET,... $extra)
 Creates an instance of the called class. More...
 

Properties

◆ $clients

WebSocketClient [] $clients = []
protected

Holds all connected clients.

Constructor

◆ __construct()

__construct (   $resource,
Reactor  $reactor 
)
Parameters
$resource
Reactor$reactor

Methods

◆ accept()

WebSocketClient accept ( )
Returns
WebSocketClient

Reimplemented from StreamServer.

◆ broadcast()

broadcast ( int  $opCode,
string  $payload 
)

Sends a payload to all clients in the OK state.

Parameters
int$opCode
string$payload

◆ broadcastBinary()

broadcastBinary ( string  $payload)
Parameters
string$payload

◆ broadcastPing()

broadcastPing ( string  $payload = '')

Sends a ping to all clients in the OK state.

Parameters
string$payload

◆ broadcastText()

broadcastText ( string  $text)

Sends a message to all clients in the OK state.

Parameters
string$text

◆ close()

$this close ( int  $code = Frame::CLOSE_INTERRUPT,
  $reason = '' 
)

Closes and removes all clients.

Parameters
int$code
string$reason
Returns
$this

◆ count()

int count ( )

The number of clients attached.

Returns
int

◆ getClients()

WebSocketClient [] getClients ( )
Returns
WebSocketClient[]

◆ newClient()

WebSocketClient newClient (   $resource)
protected
Parameters
resource$resource
Returns
WebSocketClient

Reimplemented from StreamServer.

◆ onOutOfBand()

void onOutOfBand ( )
final

WebSocket servers never get OOB data.

Implements ReactiveInterface.

◆ onReadable()

void onReadable ( )

Auto-accept.

Implements ReactiveInterface.

◆ remove()

void remove (   $client)

Removes the client from the server and reactor.

Parameters
WebSocketClient$client