FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Server Class Reference
Inheritance diagram for Server:
Thing

Public Member Functions

 __construct ($socket)
 
 ids ($controller_name=null)
 Client connection resource ID's. More...
 
 send ($id, $data)
 Send data to a client. More...
 
 broadcast ($data, $controller_name=null, $except_ids=null)
 Broadcast data to all clients. More...
 
 onLocalConnection ($connection)
 Called on a new local connection. More...
 
 onOpen (\Ratchet\ConnectionInterface $connection)
 Called on a new client connection. More...
 
 onClose (\Ratchet\ConnectionInterface $connection)
 
 onError (\Ratchet\ConnectionInterface $connection,\Exception $exception)
 
 onMessage (\Ratchet\ConnectionInterface $connection, $data)
 
 run ()
 Run the WebSocket server. More...
 
- Public Member Functions inherited from Thing
 propertyExists ($property)
 Check if a property exists (public or published). More...
 
 constants ($prefix=null)
 Return all constants. More...
 
 get ($key)
 Get one or more properties. More...
 
 set ($key, $value=null)
 Set one or more properties. More...
 
 __get ($key)
 
 __set ($key, $value)
 

Data Fields

 $clients = []
 Array with all connected clients (key = resource ID, value = Client object). More...
 
 $id = null
 Resource ID for current client. More...
 
- Data Fields inherited from Thing
const HIDDEN = 0
 Property is hidden. More...
 
const READABLE = 1
 Property is readable. More...
 
const WRITEABLE = 2
 Property is writeable. More...
 
const READWRITE = 3
 Property is readable and writeable. More...
 

Protected Member Functions

 localToken ($data)
 Create a WebSocket access token through a local connection. More...
 
 localParams ($data)
 Add or update client data (session data). More...
 
 localSessionIds ($data)
 Active session ID's through a local connection. More...
 
 localClose ($data)
 Close one or more connections through a local connection. More...
 
 localShutdown ($data)
 Request a shutdown of the WebSocket server through a local connection. More...
 
 localBroadcast ($data)
 Broadcast data to all clients through a local connection. More...
 
 onLocalData ($data)
 Local data handler. More...
 
 getLocal ()
 
 getLog ()
 
 getLoop ()
 
 getClient ()
 
 getServer ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). More...
 
 configure ($config)
 Configure the object. More...
 
 _get ($key)
 Default getter if no specific setter is defined, and the property is also not published (readable). More...
 
 _set ($key, $value)
 Default setter if no specific setter is defined, and the property is also not published (writeable). More...
 

Protected Attributes

 $_loop = null
 
 $_client = null
 Client/public WebSocket. More...
 
 $_local = null
 Local socket (raw). More...
 
 $_server = null
 
 $_socket = null
 
 $_tokens = []
 Array with allowed client tokens (key = token, value = array with keys 'time' and 'params'). More...
 
- Protected Attributes inherited from Thing
 $_published = []
 Published properties (key = name of property, value = visibility). More...
 

Detailed Description

Definition at line 5 of file Server.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $socket)

Definition at line 18 of file Server.php.

Member Function Documentation

◆ broadcast()

broadcast (   $data,
  $controller_name = null,
  $except_ids = null 
)

Broadcast data to all clients.

Parameters
mixed$data
string$controller_nameOnly to clients with this controller (empty = all).
array$except_idsExclude cients with these resource ID's.
Returns
array Resource ID's that received the data.

Definition at line 47 of file Server.php.

◆ getClient()

getClient ( )
protected

Definition at line 259 of file Server.php.

◆ getLocal()

getLocal ( )
protected

Definition at line 235 of file Server.php.

◆ getLog()

getLog ( )
protected

Definition at line 240 of file Server.php.

◆ getLoop()

getLoop ( )
protected

Definition at line 244 of file Server.php.

◆ getServer()

getServer ( )
protected

Definition at line 264 of file Server.php.

◆ ids()

ids (   $controller_name = null)

Client connection resource ID's.

Parameters
string$controller_nameGet ID's for clients with this controller (empty = all).
Returns
array

Definition at line 26 of file Server.php.

◆ localBroadcast()

localBroadcast (   $data)
protected

Broadcast data to all clients through a local connection.

Parameters
array$dataArray with a key 'data' (data to send to the clients), and optional keys 'controller' (if set only the clients with this controller will receive the data) and 'except' (if set clients with these sesion ID's will not receive the data).
Returns
array Key for 'count' (number of clients that received the data).

Definition at line 131 of file Server.php.

◆ localClose()

localClose (   $data)
protected

Close one or more connections through a local connection.

Parameters
array$dataArray with optional keys 'controller' (if set only the connections for clients with this controller are closed) and 'sessions' (if set only the connections for clients with these sesion ID's are closed).
Returns
array Key for 'count' (number of sessions closed).

Definition at line 103 of file Server.php.

◆ localParams()

localParams (   $data)
protected

Add or update client data (session data).

Parameters
array$dataArray with key 'sessionId'. All other data is merged with the client data.
Returns
array Key for 'count' (number of data sets modified).

Definition at line 68 of file Server.php.

◆ localSessionIds()

localSessionIds (   $data)
protected

Active session ID's through a local connection.

Parameters
array$dataArray with an optional key 'controller' (if set only the session ID' for clients with this controller are returned).
Returns
array Key for 'sessionIds' (array with active session ID's).

Definition at line 89 of file Server.php.

◆ localShutdown()

localShutdown (   $data)
protected

Request a shutdown of the WebSocket server through a local connection.

Parameters
array$dataExpects nothing.

Definition at line 120 of file Server.php.

◆ localToken()

localToken (   $data)
protected

Create a WebSocket access token through a local connection.

Parameters
array$dataArray with a key for the 'token'.
Returns
array Key for 'time' until which the token is valid.

Definition at line 57 of file Server.php.

◆ onClose()

onClose ( \Ratchet\ConnectionInterface  $connection)

Definition at line 205 of file Server.php.

◆ onError()

onError ( \Ratchet\ConnectionInterface  $connection,
\Exception  $exception 
)

Definition at line 210 of file Server.php.

◆ onLocalConnection()

onLocalConnection (   $connection)

Called on a new local connection.

Parameters
\React\Socket\ConnectionInterface$connection

Definition at line 158 of file Server.php.

◆ onLocalData()

onLocalData (   $data)
protected

Local data handler.

Parameters
mixed$dataData received from HTTP server.
Returns
mixed Response to HTTP server.
See also
send()

Definition at line 144 of file Server.php.

◆ onMessage()

onMessage ( \Ratchet\ConnectionInterface  $connection,
  $data 
)

Definition at line 215 of file Server.php.

◆ onOpen()

onOpen ( \Ratchet\ConnectionInterface  $connection)

Called on a new client connection.

Parameters
\Ratchet\ConnectionInterface$connection

Definition at line 176 of file Server.php.

◆ run()

run ( )

Run the WebSocket server.

Definition at line 231 of file Server.php.

◆ send()

send (   $id,
  $data 
)

Send data to a client.

Parameters
int$idClient connection resource ID.
mixed$data

Definition at line 37 of file Server.php.

Field Documentation

◆ $_client

$_client = null
protected

Client/public WebSocket.

Definition at line 11 of file Server.php.

◆ $_local

$_local = null
protected

Local socket (raw).

Definition at line 12 of file Server.php.

◆ $_loop

$_loop = null
protected

Definition at line 10 of file Server.php.

◆ $_server

$_server = null
protected

Definition at line 13 of file Server.php.

◆ $_socket

$_socket = null
protected

Definition at line 15 of file Server.php.

◆ $_tokens

$_tokens = []
protected

Array with allowed client tokens (key = token, value = array with keys 'time' and 'params').

Definition at line 16 of file Server.php.

◆ $clients

$clients = []

Array with all connected clients (key = resource ID, value = Client object).

Definition at line 7 of file Server.php.

◆ $id

$id = null

Resource ID for current client.

Definition at line 8 of file Server.php.


The documentation for this class was generated from the following file: