walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.03k stars 2.25k forks source link

AsyncTcpConnection error when using 'wss' #960

Closed mcigorli closed 9 months ago

mcigorli commented 9 months ago

Hello everyone I want to connect and receive financial quotes. Only the wss method is offered. "wss://marketdelta.tradermade.com/feedadv" My code:

$connection_local_price = new AsyncTcpConnection('wss://marketdata.tradermade.com/feedadv');
$connection_local_price->onConnect = function($connection_local_price) use (&$tests)
{
    $mass_send = [
        'userKey' => 'wsOPxDXxz3chLexHG0YQ',
        'symbol' => 'EURUSD,USDCAD,GBPUSD'
    ];
    $mass_send = json_encode($mass_send);
    $connection_local_price->send($mass_send);
};
$connection_local_price->onMessage = function ($connection_local_price,$data) use (&$connection,&$tests)
{
    $connection->send($data);
};
$connection_local_price->onClose = function($connection_local_price) use (&$tests)
{
    $connection_local_price->reConnect(0);
};
$connection_local_price->connect();

After starting the server, I get an error in 'workerman.log'

2023-10-05 17:07:49 pid:1232794 Exception: class \Protocols\Wss not exist in /var/www/www-root/data/workerman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php:150
Stack trace:
#0 /var/www/www-root/data/workerman/ChatWorkerT.php(46): Workerman\Connection\AsyncTcpConnection->__construct()
#1 /var/www/www-root/data/workerman/vendor/workerman/workerman/Protocols/Websocket.php(392): {closure}()
#2 /var/www/www-root/data/workerman/vendor/workerman/workerman/Protocols/Websocket.php(57): Workerman\Protocols\Websocket::dealHandshake()
#3 /var/www/www-root/data/workerman/vendor/workerman/workerman/Connection/TcpConnection.php(619): Workerman\Protocols\Websocket::input()
#4 /var/www/www-root/data/workerman/vendor/workerman/workerman/Events/Select.php(292): Workerman\Connection\TcpConnection->baseRead()
#5 /var/www/www-root/data/workerman/vendor/workerman/workerman/Worker.php(2410): Workerman\Events\Select->loop()
#6 /var/www/www-root/data/workerman/vendor/workerman/workerman/Worker.php(1543): Workerman\Worker->run()
#7 /var/www/www-root/data/workerman/vendor/workerman/workerman/Worker.php(1373): Workerman\Worker::forkOneWorkerForLinux()
#8 /var/www/www-root/data/workerman/vendor/workerman/workerman/Worker.php(1347): Workerman\Worker::forkWorkersForLinux()
#9 /var/www/www-root/data/workerman/vendor/workerman/workerman/Worker.php(547): Workerman\Worker::forkWorkers()
#10 /var/www/www-root/data/workerman/ChatWorkerT.php(86): Workerman\Worker::runAll()
#11 {main}
2023-10-05 17:07:49 pid:1232794 Worker[1232794] process terminated
2023-10-05 17:07:49 pid:1232793 worker[none:1232794] exit with status 64000

Why is the wss connection not working via Async Tcp Connection ? p.s If I use another server where the ws method works, then the connection works successfully.

fuzqing commented 9 months ago
// change wss to ws
// 443 is the wss server port
$connection_local_price = new AsyncTcpConnection('ws://marketdata.tradermade.com:443/feedadv');
// dont forget this line
$connection_local_price->transport = 'ssl';
mcigorli commented 9 months ago
// change wss to ws
// 443 is the wss server port
$connection_local_price = new AsyncTcpConnection('ws://marketdata.tradermade.com:443/feedadv');
// dont forget this line
$connection_local_price->transport = 'ssl';

It's just chumaa) Thank you very much, it works!