<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Connection\AsyncTcpConnection;
// SSL context.
$context = [ 'ssl' => [ 'local_cert' => '/etc/letsencrypt/live/utelimited.ru/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/utelimited.ru/privkey.pem',
'verify_peer' => false,
]
];
// Create a Websocket server
$ws_worker = new Worker ("websocket://0.0.0.0:100", $context);
$ws_worker->transport = 'ssl';
// Emitted when new connection come
$ws_worker-> onConnect = function($connection)
{
$connection->onWebSocketConnect = function($connection)
{
echo "New connection\n";
$connection->send ('Server OK: ' . $data);
};
};
// Emitted when data received
$ws_worker-> onMessage = function($connection, $data)
{
// Send hello $data
$connection->send ('hello ' . $data);
};
// Emitted when connection closed
$ws_worker-> onClose = function($connection)
{
echo "Connection closed\n";
};
//===============================
$worker_wss = new Worker ();
$worker_wss ->onWorkerStart = function ($ws_worker) {
// Websocket protocol for client.
$ws_connection = new AsyncTcpConnection('ws://ws.eodhistoricaldata.com/ws/crypto?api_token=demo');
$ws_connection-> onConnect = function ($connection_wss) use (&$ws_worker) {
//$connection_wss-> send ('Hello_WSS_NEW');
foreach($ws_worker->connections as $connection) {
$connection->send($data);
}
};
$ws_connection->onMessage = function ($connection_wss, $data) use (&$ws_worker) {
foreach($ws_worker->connections as $connection) {
$connection->send($data);
}
};
$ws_connection->onError = function ($connection_wss, $code, $msg) {
echo "Error: $msg\n";
};
$ws_connection->onClose = function ($connection_wss) {
echo "Connection closed\n";
};
$ws_connection->connect();
};
// Run worker
Worker::runAll();
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Connection \AsyncTcpConnection;
// SSL context.
$context = [ 'ssl' => [ 'local_cert' => '/etc/letsencrypt/live/utelimited.ru/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/utelimited.ru/privkey.pem',
'verify_peer' => false,
]
];
// Create a Websocket server
$ws_worker = new Worker ("websocket://0.0.0.0:2346", $context);
$worker->transport = 'ssl';
// Emitted when new connection come
$ws_worker-> onConnect = function($connection)
{
echo "New connection\n";
};
// Emitted when data received
$ws_worker-> onMessage = function($connection, $data)
{
// Send hello $data
$connection->send ('hello ' . $data);
};
// Emitted when connection closed
$ws_worker-> onClose = function($connection)
{
echo "Connection closed\n";
};
//===============================
$worker_wss = new Worker ();
$worker_wss ->onWorkerStart = function () {
// Websocket protocol for client.
$ws_connection = new AsyncTcpConnection('ws://ws.eodhistoricaldata.com/ws/crypto?api_token=demo');
$ws_connection-> onConnect = function ($connection_wss) {
$connection_wss-> send ('Hello');
};
$ws_connection->onMessage = function ($connection_wss, $data) {
echo "Recv: $data\n";
};
$ws_connection->onError = function ($connection_wss, $code, $msg) {
echo "Error: $msg\n";
};
$ws_connection->onClose = function ($connection_wss) {
echo "Connection closed\n";
};
$ws_connection->connect();
};
// Run worker
Worker::runAll();
@hollywood_men