tansoft / websocketclient
websocket client lib
Installs: 267
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 2
Open Issues: 0
Type:project
Requires
- textalk/websocket: 1.0.*
Requires (Dev)
- textalk/websocket: 1.0.*
This package is not auto-updated.
Last update: 2025-03-22 18:43:14 UTC
README
Simple websocket client and support data record and playback.
Depend on project Textalk/websocket.
Installing
Preferred way to install is with Composer.
composer require tansoft/websocketclient
Client usage:
require('vendor/autoload.php'); class MyHandler implements WebSocket\ISocketHandler{ public function onConnect(&$client){ //init send something $client->send($reg); } public function onReceive(&$client, $msg){ //receive something with $msg //return false for exit return true; } public function onError(&$client, $errno, $errmsg){ echo('socket error '.$errno.':'.$errmsg); //return true for auto reconnect return true; } } $client = new WebSocket\WebSocketClient('ws://echo.websocket.org/', new MyHandler); //setup auto ack settings $client->setupAck('{"event":"ping"}', '{"event":"pong"}', KEEPALIVE_TIMEOUT_SECOND); //setup rawdata record $client->setupRawLog('rawdata.log'); $client->loop(); //or //setup rawdata playback //use flag WebSocket\WebSocketClient::RAWLOG_PLAYBACKMODE_QUICK for playback with no sleep $client->setupRawLog('rawdata.log', WebSocket\WebSocketClient::RAWLOG_PLAYBACKMODE_NORMAL); $client->loop();
Changelog
1.0.0
- Support auto ack.
- Support event base callback.
- Support rawdata record and playback.