I'm using https://github.com/orchidsoftware/web-socket in my laravel project and I want to send messages to clients connected.
So far I've followed the README and got the server up and running - I get the alert "The connection is established.".
But when I try to send a message to the client, nothing happens. I've created a sendMessageToAll function and tried to call it both from onOpen and from another controller:
public function onOpen(ConnectionInterface $conn)
{
$this->clients->attach($conn);
$this->sendMessageToAll("message");
}
public function sendMessageToAll($msg){
foreach ($this->clients as $client) {
$client->send($msg);
}
}
And from another controller:
public function test() {
$ws = new WebSocketClass();
$ws->sendMessageToAll("testing");
}
Is there something I'm missing in order to get it up and running?
from Sending message to client with Web Sockets
No comments:
Post a Comment