Aerys\Websocket\Endpoint::send PHP Method

send() public method

public send ( $clientId, string $data ) : Amp\Promise
$data string
return Amp\Promise
    public function send($clientId, string $data) : Promise;

Usage Example

Example #1
0
 public function onData(int $clientId, Websocket\Message $msg)
 {
     // yielding $msg buffers the complete payload into a single string. For very large payloads, you may want to
     // stream those instead of buffering them.
     $body = (yield $msg);
     // We use the IP as name for this simple chat app.
     $ip = $this->connections[$clientId];
     // If someone mentions an IP, we send the message only to clients with that IP and the sender itself.
     if (preg_match("~@(\\d+\\.\\d+\\.\\d+\\.\\d+)\\b~", $body, $match)) {
         list($all, $receiver) = $match;
         $payload = $ip . " (private): " . substr($body, strlen($all));
         $clients = array_keys($this->ips[$receiver] ?? []);
         if (!empty($clients)) {
             $this->endpoint->send($clients, $payload);
         }
         $this->endpoint->send($clientId, $payload);
     } else {
         $payload = $ip . ": " . $body;
         $this->endpoint->send(null, $payload);
     }
 }
All Usage Examples Of Aerys\Websocket\Endpoint::send