Skip to content

heart break #10

Answered by sirn-se
s2828 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, by using the subscription flow with listeners.

Use onText() and possibly onBinary() to handle incoming messages. Then use onTick() to push ping messages to server at interval.

Something like this;

$client = new WebSocket\Client("ws://echo.websocket.org/");
$client
    // Add standard middlewares
    ->addMiddleware(new WebSocket\Middleware\CloseHandler())
    ->addMiddleware(new WebSocket\Middleware\PingResponder())
    // Listen to incoming messages
    ->onText(function (WebSocket\Client $client, WebSocket\Connection $connection, WebSocket\Message\Message $message) {
        // Act on incoming message
    })
    ->onBinary(function (WebSocket\Client $client, WebSocket\Connection $c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sirn-se
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants