Skip to content

Add WebSocket client implementation#6

Merged
thekid merged 24 commits intomasterfrom
feature/ws-client
Oct 5, 2024
Merged

Add WebSocket client implementation#6
thekid merged 24 commits intomasterfrom
feature/ws-client

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Oct 4, 2024

Example

use util\cmd\Console;
use websocket\WebSocket;

$remote= $argv[1] ?? 'wss://echo.websocket.events';
Console::writeLine('@@@ Connect ', $remote);
$s= new WebSocket($remote);
$s->connect();

Console::writeLine('<<< ', $s->receive());

$send= $argv[2] ?? 'Test!';
Console::writeLine('>>> ', $send);
$s->send($send);
Console::writeLine('<<< ', $s->receive());

Console::writeLine('>>> Ping');
$s->ping();
Console::writeLine('<<< ', $s->receive());

$s->close();

See https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

@thekid thekid added the enhancement New feature or request label Oct 4, 2024
* @return void
*/
public function close($connection) { /* NOOP */ }
public function close($connection, $code, $reason) { /* NOOP */ }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break - all Listener implementations with a close() method need to be adapted!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thekid thekid merged commit 9bb66e9 into master Oct 5, 2024
thekid added a commit to thekid/crews that referenced this pull request Oct 5, 2024
@thekid thekid deleted the feature/ws-client branch October 5, 2024 10:57
@thekid thekid mentioned this pull request Jan 12, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant