30 public function action($controller_name,$action,$params = null,$read_length = 1024){
32 if($this->localPort && ($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)))
try{
34 socket_connect($socket,$this->localHost,$this->localPort) &&
35 (socket_write($socket,serialize(array_merge($params ?: [],[
'controller' => $controller_name,
'action' => $action]))) !==
false)
36 ) $result = socket_read($socket,$read_length);
37 socket_close($socket);
40 $this->
component(
'log')->emergency(
'Can not connect to socket server: ' . $e->getMessage(),__FILE__,__LINE__);
42 return $result ? unserialize($result) : $result;
49 public function token($params = null){
50 if(!$this->clientPort)
return null;
51 $params = array_merge($params ?: [],[
'token' => $token = \
Rsi\Str::random(),
'sessionId' => session_id()]);
52 return $this->
action(null,
'token',$params) ===
false ? false : $token;
56 if(!$this->_server) $this->_server =
new Socket\Server($this);
$clientLocalPort
When the WebSocket server should listen on another local port then the client connects.
$clientPort
Port client websockets can connect to (empty = no connection allowed).
$clientOrigins
Allowed origins (empty = all).
$clientPrefix
Prefix for websocket requests (for example when tunneling WSS traffic).
$localClients
Allowed clients for a local connection.
$localPort
Port for local connections (HTTP server <-> WebSocket server).
action($controller_name, $action, $params=null, $read_length=1024)
Request an action from the HTTP Server on the WebSocket server.
$clientHost
Host the WebSocket server is running on (for public connections; empty = same as HTTP).
$localHost
Host the WebSocket server is running on (for local connections).
$_server
WebSocket server.
token($params=null)
Create a WebSocket access token.
$tokenTtl
Time a request token is valid (seconds).
component($name)
Get a component (local or default).