Ratchet Websocket 无法从客户端接收数据?

编程入门 行业动态 更新时间:2024-10-26 02:32:13
本文介绍了Ratchet Websocket 无法从客户端接收数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有框架 Symfony 的实时 Web 应用程序.我需要将数据从客户端发送到 websket 服务器.所以我尝试了这个:

I have a real time web application with the frameWork Symfony. I need to send data from client to the webscket server.so I have try this :

var conn = new WebSocket('ws://127.0.0.1:8080'); console.log (conn); conn.onopen = function (e) { console.log ("Connection established!"); conn.send("xoxo"); };

它没有显示任何错误,在服务器端我有这个:服务器代码:

It does't show any error and in the server side I have this : The Server Code :

$app=new AggregateApplication(); $loop = \React\EventLoop\Factory::create(); $context = new \React\ZMQ\Context($loop); $pull = $context->getSocket(\ZMQ::SOCKET_PULL); $pull->bind('tcp://127.0.0.1:5555'); $pull->on('message', array($app, 'EditMessage')); $webSock = new \React\Socket\Server($loop); $webSock->listen(8080, '127.0.0.1'); $handler = $this->getContainer()->get('session.handler'); $server=new \Ratchet\Wamp\WampServer($app); $server = new SessionProvider($server, $handler); $webServer = new \Ratchet\Server\IoServer(new \Ratchet\WebSocket\WsServer($server),$webSock); $loop->run();

这是我的应用代码:

class AggregateApplication implements WampServerInterface { protected $clients; protected $comming; public function __construct() { $this->clients = array(); $this->comming = array(); } public function onOpen(ConnectionInterface $conn){ $this->clients[array_shift($this->comming)]=$conn; echo "New connection! ".array_shift($this->comming)." ({$conn->resourceId})\n"; } public function onCall(ConnectionInterface $conn, $id, $topic, array $params){ } public function onSubscribe(ConnectionInterface $conn, $topic){ echo "onSubscribe"; } public function onUnSubscribe(ConnectionInterface $conn, $topic){ } public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible){ } public function onClose(ConnectionInterface $conn) { unset($this->clients[array_search($conn, $this->clients)]); echo 'close connection '; } public function onError(ConnectionInterface $conn, \Exception $e) { } }

我找不到的问题是我会捕捉到客户端发送的消息吗?

The problem I can't find were I ll catch the message sent from client?

推荐答案

您的消息不符合 WAMP 标准.查看 AutobahnJS 以了解您的客户端连接.另请查看棘轮推送集成教程,其中有一个功能示例.

Your message does not conform to the WAMP standard. Take a look at AutobahnJS for your client connection. Also take a look at the Ratchet Push Integration Tutorial, which has a functional example.

更多推荐

Ratchet Websocket 无法从客户端接收数据?

本文发布于:2023-10-26 19:15:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   数据   Ratchet   Websocket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!