@hollanditkzn

Как исправить ошибку в консоле ratched?

У меня такая проблема делал так как написано в документации http://socketo.me/docs/push, но в консоле выходит ошибка
Exception 'ZMQSocketException' with message 'Failed to bind the ZMQ: Invalid argument'
Как здесь быть, может я что-то не правильно понимаю в документации
Как я реализовал в 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){}
}

И в контроллере console/controllers/SocketController
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();
    }
}

Кто подскажет как исправить ошибку?
  • Вопрос задан
  • 162 просмотра
Пригласить эксперта
Ответы на вопрос 1
Austin_Powers
@Austin_Powers
Web developer (Symfony, Go, Vue.js)
В документации ip прописывают вместе с портом.
Попробуйте так, может решит проблему:
$pull->bind('tcp://127.0.0.1:' . $port);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы