-
Notifications
You must be signed in to change notification settings - Fork 0
WebSockets
This class is required when using WebSockets support within the library.
To run a WebSockets Server, you need to first initiate this class with a function that accepts two arguments: a client connection & a message.
This function must be called first to use WebSockets.
It accepts an argument which is a function which will handle any messages coming from any client.
Example:
\APLib\WebSockets::init(
function($client, $message){
echo "A client with the IP address '{$client->remoteAddress}' sent: {$message}\r\n";
}
);
The argument function will get called every time a client sends a message.
This function is called when ever a client sends a message and then passes the client along with the message received to the function you pass to init function.
NOTE: DO NOT CALL THIS FUNCTION MANUALLY
This function adds a client to the list of active clients and assigns an Array object containing three keys:
"verified" => false,
"key" => null,
"ip" => "CLIENT_IP"
These three keys can be used to verify a client and authorize it (if necessary).
The keys can be get using get function & set using set function.
NOTE: DO NOT CALL THIS FUNCTION MANUALLY
This function removes a client from the list of active clients.
NOTE: DO NOT CALL THIS FUNCTION MANUALLY. IF YOU NEED TO REMOVE A CLIENT, JUST CLOSE THE CONNECTION USING $client->close();
This function sets the data associated with the client.
Example:
\APLib\WebSockets::set($client, $data);
NOTE: $data COULD BE ANYTHING AND WILL OVERRIDE THE EXISTING DATA.
This function gets the data associated with the client.
By default, this function would return the Array object assigned with the client in add function.