Answer the question
In order to leave comments, you need to log in
How to fix error in ratched console?
I did such a problem as it is written in the documentation http://socketo.me/docs/push, but in the console an error occurs
Exception 'ZMQSocketException' with message 'Failed to bind the ZMQ: Invalid argument'
How can I be here, maybe I -something I don't understand correctly in the documentation
How I implemented in console/model/SocketServer
namespace console\models;
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\Topic;
use Ratchet\Wamp\WampServerInterface;
use yii\helpers\Html;
class SocketServer implements WampServerInterface
{
protected $subscribedTopic = [];
public function onSubscribe(ConnectionInterface $conn, $topic)
{
$subject = $topic->getId();
if (!array_key_exists($subject, $this->subscribedTopic)){
$this->subscribedTopic[$subject] = $topic;
}
}
public function onPushEventData($event)
{
$eventData = json_decode($event, true);
if (!array_key_exists($eventData['subscribeKey'], $this->subscribedTopic)){
return;
}
$topic = $this->subscribedTopic[$eventData['subscribeKey']];
if ($topic instanceof Topic) {
foreach ($eventData as $eventField => &$fieldValue)
$fieldValue = Html::encode($fieldValue);
$topic->broadcast($eventData);
} else {
return;
}
}
public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
{
$conn->callError($id, $topic, 'You are not allowed to make calls')->close();
}
public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible)
{
$conn->close();
}
public function onUnSubscribe(ConnectionInterface $conn, $topic){}
public function onOpen(ConnectionInterface $conn){}
public function onClose(ConnectionInterface $conn){}
public function onError(ConnectionInterface $conn, \Exception $e){}
}
namespace console\controllers;
use console\models\SocketServer;
use React\EventLoop\Factory;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\Wamp\WampServer;
use Ratchet\WebSocket\WsServer;
use React\Socket\Server;
use React\ZMQ\Context;
use yii\console\Controller;
class SocketController extends Controller
{
public function actionStartSocket($port = 5555)
{
$loop = Factory::create();
$pusher = new SocketServer();
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new Context($loop);
$pull = $context->getSocket(\ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:', $port); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', [$pusher, 'onPushEventData']);
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new Server($loop);
$webSock->listen(8080, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new IoServer(
new HttpServer(
new WsServer(
new WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question