mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-11-26 11:54:42 +01:00
websocket-events add reconection loop.
This commit is contained in:
parent
2a1e2aeada
commit
9acd4e6c33
@ -23,22 +23,25 @@ $options = [
|
||||
Amp\Loop::run(static function () use($options) {
|
||||
echo "Connecting to: {$options['url']}" . PHP_EOL;
|
||||
|
||||
try {
|
||||
/** @var Connection $connection */
|
||||
$connection = yield connect($options['url']);
|
||||
while(true) {
|
||||
try {
|
||||
/** @var Connection $connection */
|
||||
$connection = yield connect($options['url']);
|
||||
|
||||
$connection->onClose(static function() use($connection) {
|
||||
printf("Connection closed. Reason: %s\n", $connection->getCloseReason());
|
||||
});
|
||||
$connection->onClose(static function() use($connection) {
|
||||
printf("Connection closed. Reason: %s\n", $connection->getCloseReason());
|
||||
});
|
||||
|
||||
echo 'Waiting for events...' . PHP_EOL;
|
||||
while ($message = yield $connection->receive()) {
|
||||
/** @var Message $message */
|
||||
$payload = yield $message->buffer();
|
||||
printf("Received event: %s\n", $payload);
|
||||
echo 'Waiting for events...' . PHP_EOL;
|
||||
while ($message = yield $connection->receive()) {
|
||||
/** @var Message $message */
|
||||
$payload = yield $message->buffer();
|
||||
printf("Received event: %s\n", $payload);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
printf("Error: %s\n", $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
printf("Error: %s\n", $e->getMessage());
|
||||
yield new Amp\Delayed(500);
|
||||
}
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user