summaryrefslogtreecommitdiffstats
path: root/vendor/textalk/websocket/docs/Examples.md
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:26:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:26:02 +0000
commitfcbf3ce37ca8f90a3e36d524a3274ffc063a40e3 (patch)
tree84c735df2e97350a721273e9dd425729d43cc8a2 /vendor/textalk/websocket/docs/Examples.md
parentInitial commit. (diff)
downloadicingaweb2-module-pdfexport-upstream.tar.xz
icingaweb2-module-pdfexport-upstream.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/docs/Examples.md')
-rw-r--r--vendor/textalk/websocket/docs/Examples.md98
1 files changed, 98 insertions, 0 deletions
diff --git a/vendor/textalk/websocket/docs/Examples.md b/vendor/textalk/websocket/docs/Examples.md
new file mode 100644
index 0000000..7dd4e0c
--- /dev/null
+++ b/vendor/textalk/websocket/docs/Examples.md
@@ -0,0 +1,98 @@
+[Client](Client.md) • [Server](Server.md) • [Message](Message.md) • Examples • [Changelog](Changelog.md) • [Contributing](Contributing.md)
+
+# Websocket: Examples
+
+Here are some examples on how to use the WebSocket library.
+
+## Echo logger
+
+In dev environment (as in having run composer to include dev dependencies) you have
+access to a simple echo logger that print out information synchronously.
+
+This is usable for debugging. For production, use a proper logger.
+
+```php
+namespace WebSocket;
+
+$logger = new EchoLogger();
+
+$client = new Client('ws://echo.websocket.org/');
+$client->setLogger($logger);
+
+$server = new Server();
+$server->setLogger($logger);
+```
+
+An example of server output;
+```
+info | Server listening to port 8000 []
+debug | Wrote 129 of 129 bytes. []
+info | Server connected to port 8000 []
+info | Received 'text' message []
+debug | Wrote 9 of 9 bytes. []
+info | Sent 'text' message []
+debug | Received 'close', status: 1000. []
+debug | Wrote 32 of 32 bytes. []
+info | Sent 'close' message []
+info | Received 'close' message []
+```
+
+## The `send` client
+
+Source: [examples/send.php](../examples/send.php)
+
+A simple, single send/receive client.
+
+Example use:
+```
+php examples/send.php --opcode text "A text message" // Send a text message to localhost
+php examples/send.php --opcode ping "ping it" // Send a ping message to localhost
+php examples/send.php --uri ws://echo.websocket.org "A text message" // Send a text message to echo.websocket.org
+php examples/send.php --opcode text --debug "A text message" // Use runtime debugging
+```
+
+## The `echoserver` server
+
+Source: [examples/echoserver.php](../examples/echoserver.php)
+
+A simple server that responds to recevied commands.
+
+Example use:
+```
+php examples/echoserver.php // Run with default settings
+php examples/echoserver.php --port 8080 // Listen on port 8080
+php examples/echoserver.php --debug // Use runtime debugging
+```
+
+These strings can be sent as message to trigger server to perform actions;
+* `exit` - Server will initiate close procedure
+* `ping` - Server will send a ping message
+* `headers` - Server will respond with all headers provided by client
+* `auth` - Server will respond with auth header if provided by client
+* For other sent strings, server will respond with the same strings
+
+## The `random` client
+
+Source: [examples/random_client.php](../examples/random_client.php)
+
+The random client will use random options and continuously send/receive random messages.
+
+Example use:
+```
+php examples/random_client.php --uri ws://echo.websocket.org // Connect to echo.websocket.org
+php examples/random_client.php --timeout 5 --fragment_size 16 // Specify settings
+php examples/random_client.php --debug // Use runtime debugging
+```
+
+## The `random` server
+
+Source: [examples/random_server.php](../examples/random_server.php)
+
+The random server will use random options and continuously send/receive random messages.
+
+Example use:
+```
+php examples/random_server.php --port 8080 // // Listen on port 8080
+php examples/random_server.php --timeout 5 --fragment_size 16 // Specify settings
+php examples/random_server.php --debug // Use runtime debugging
+```