我的问题是针对棘轮/Pawl使用松弛的rtm。我有下面的代码,它连接得很好,但最终会死。
<?php
require_once "response.php";
//first make authenticated call to rtm.start
use \Curl\Curl;
$curl = new Curl();
$rtmStartUrl = "https://slack.com/api/rtm.start?token=xx-xx-xx-xx-xx&pretty=1";
$curl->get($rtmStartUrl);
$wsUrl = $curl->response->url;
$loop = React\EventLoop\Factory::create();
$connector = new Ratchet\Client\Connector($loop);
$connector($wsUrl)
->then(function(Ratchet\Client\WebSocket $conn) {
$conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
echo "Received: {$msg}\n";
// $conn->close();
});
$conn->on('close', function($code = null, $reason = null) {
echo "Connection closed ({$code} - {$reason})\n";
});
$conn->send('Hello World!');
}, function(\Exception $e) use ($loop) {
echo "Could not connect: {$e->getMessage()}\n";
$loop->stop();
});
$loop->run();在运行时,输出是:
root@ip-172-31-45-75:/var/www/html/slack# php pawl.php
Received: {"type":"hello"}
Received: {"type":"reconnect_url","url":"wss://mpmulti-qpau.slack-msgs.com/websocket/jDkgDysXfZspRj10zqdcrshHK6PhPLItYx2HEkdXy47RPCAJwKgI_NLq0bhS4uMjIT7iRtOoCDUJffcxcr7YdiqMbITUZYqnTmT39Et5a8JeuPLFfCUUzan4MCz34p0jcfAKaQW9G9HpIWrYH4CTqyICZuhgWHnzo8K7dO2zXFc="}
Received: {}
Connection closed (1006 - Underlying connection closed)
root@ip-172-31-45-75:/var/www/html/slack# websocket是松弛rtm (https://api.slack.com/rtm)的一部分。在空的websocket上阅读时,连接似乎是关闭的。我认为这可能就像我们收听通过websocket发送的空闲事件(https://api.slack.com/events),以避免断开连接。
目前,由于断开连接错误,此操作无法工作。
发布于 2016-04-28 06:52:08
Hello World!不是此API的有效消息,因此当它接收到该消息时,它将关闭连接。尝试发送一些有效的东西(或者什么也不发送)。
https://stackoverflow.com/questions/36904783
复制相似问题