Open varun7952 opened 1 year ago
@varun7952 Thanks for bringing this up :+1:
I can see in your example above that you use SplObjectStorage
in order to store your clients, attach them inside the onOpen()
method and detach them in onClose()
. So it seems to me that you're already keeping track of your connected clients, what exactly is the problem you're facing here (What makes you think it doesn't work)?
@SimonFrings Is there any method or function which i can call to get ID of users currently connected to websocket. Right now i am doing it by saving user id at onOpen in text file and delete at onClose but i guess this is the hack not a solution. Can you please look at this point ?
@varun7952 you may also want to store the connected clients in a PHP array.
// ...
public function onOpen(ConnectionInterface $conn)
{
$this->clients[$conn->resourceId] = $conn;
// ...
}
// ...
Then, the ids can be obtained using PHP's built-in function array_keys.
array_keys($this->clients);
I am trying my hands on websockets and i think its working too. I created a dummy php file to start a websocket server then at onOpen i am attaching to user ID of each clients so i can access it later or can use their ID to send message to them. After starting and connecting to the websocket, i try to access list of users connected to the websocket like this
This file shows error that port is already in use, its right because websocket server is running on 20081 port and all users connected to websocket on this port too.
Websocket
I stuck to get connected users from websocket, but not able to find any docs or help which can help me to get active/connected users (with their IDs).