Method
WebSocket::receive
The next text or binary message, or null once the connection is closed.
Description#
public WebSocket::receive(): ?stringClosed by the client, by end(), or because the client broke the protocol. When the
worker stops, swerve closes it (1001, or 1012 on a reload) and this throws a
WorkerStoppingException. Waits for a message. It is the alternative to $onMessage, and
the two don't mix.
Return values#
?string
Errors / Exceptions#
| Exception | When |
|---|---|
LogicException | While $onMessage has listeners: they get the messages |
Examples#
while (null !== ($message = $ws->receive())) {
$ws->send(strrev($message));
}See also#
WebSocket::isBinaryWhether the messagereceive()returned last was binary, rather than text.