diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:26:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:26:02 +0000 |
commit | fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3 (patch) | |
tree | 84c735df2e97350a721273e9dd425729d43cc8a2 /vendor/textalk/websocket/examples/send.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-pdfexport-fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3.tar.xz icingaweb2-module-pdfexport-fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3.zip |
Adding upstream version 0.10.2+dfsg1.upstream/0.10.2+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/textalk/websocket/examples/send.php')
-rw-r--r-- | vendor/textalk/websocket/examples/send.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/textalk/websocket/examples/send.php b/vendor/textalk/websocket/examples/send.php new file mode 100644 index 0000000..30e48e0 --- /dev/null +++ b/vendor/textalk/websocket/examples/send.php @@ -0,0 +1,51 @@ +<?php + +/** + * Simple send & receive client for test purpose. + * Run in console: php examples/send.php <options> <message> + * + * Console options: + * --uri <uri> : The URI to connect to, default ws://localhost:8000 + * --opcode <string> : Opcode to send, default 'text' + * --debug : Output log data (if logger is available) + */ + +namespace WebSocket; + +require __DIR__ . '/../vendor/autoload.php'; + +error_reporting(-1); + +echo "> Send client\n"; + +// Server options specified or random +$options = array_merge([ + 'uri' => 'ws://localhost:8000', + 'opcode' => 'text', +], getopt('', ['uri:', 'opcode:', 'debug'])); +$message = array_pop($argv); + +// If debug mode and logger is available +if (isset($options['debug']) && class_exists('WebSocket\EchoLog')) { + $logger = new EchoLog(); + $options['logger'] = $logger; + echo "> Using logger\n"; +} + +try { + // Create client, send and recevie + $client = new Client($options['uri'], $options); + $client->send($message, $options['opcode']); + echo "> Sent '{$message}' [opcode: {$options['opcode']}]\n"; + if (in_array($options['opcode'], ['text', 'binary'])) { + $message = $client->receive(); + $opcode = $client->getLastOpcode(); + if (!is_null($message)) { + echo "> Got '{$message}' [opcode: {$opcode}]\n"; + } + } + $client->close(); + echo "> Closing client\n"; +} catch (\Throwable $e) { + echo "ERROR: {$e->getMessage()} [{$e->getCode()}]\n"; +} |