WebSocketServer - ThomasDupont/php_websocket GitHub Wiki

WebSocketServer documentation

abstract class WebSocketServer

__construct(string $host = "localhost", int $port = 9001)

create a websocket with the $host and $port specified


abstract protected void operation (Socket $changedSocket)

The operation to do after a client message, $changedSocket is the client socket. This method could be linked with a model. To perform a notification loop, please use a thread. php Threads

abstract protected void push(array $args = [])

Push a message to clients, the optional arguments contain all needing to perform the action.


public methods

public array getClients ()

Get all connected clients, format: array(['token' => $token, 'client' => $socket], ... ).

public int getnbUsersConnected()

Get the total number of connected clients.

public string getInputStream()

Get the message send by the connected client, the client have to send a JSON object.

public WebSocketServer setOutputStream (array $output)

Set the response before sending to the client. The array will be encoding to JSON.

protected void pushToClient(array $clients)

Send the response to the array of clients, format: array(['token' => $token, 'client' => $socket], ... ).


protected methods

protected void onConnect(stdClass $args)

Perform action for each connection, $args format: ['ip' => $ip, 'socket' => ['token' => $token, 'client'=> $socket]].

protected void onDisconnect(stdClass $args)

Perform action for each disconnection, $args format: ['ip' => $ip, 'socket' => ['token' => $token, 'client'=> $socket]].