我已经编译并运行了本指南中的代码:
http://spring.io/guides/gs/messaging-stomp-websocket/
我想使用this Stomp PHP库连接到在本地主机端口8080上启动的服务器。
这是我用来连接Spring服务器的代码:
<?php
// include a library
require_once("Stomp.php");
// make a connection
$con = new Stomp("tcp://localhost:8080");
// connect
$con->connect();
// send a message to the queue
$con->send("/hello", "test");
echo "Sent message with body 'test'\n";
// subscribe to the queue
$con->subscribe("/topic/greetins");
// receive a message from the queue
$msg = $con->readFrame();
// do what you want with the message
if ( $msg != null) {
echo "Received message with body '$msg->body'\n";
// mark the message as received in the queue
$con->ack($msg);
} else {
echo "Failed to receive a message\n";
}
// disconnect
$con->disconnect();代码将在尝试从服务器接收响应的while循环中结束,该响应在file: Stomp.php中尝试接收帧。
接下来是来自服务器的响应:
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Date: Fri, 08 Aug 2014 18:11:23 GMT
Connection: close我哪里做错了?
发布于 2015-05-08 02:03:38
下面是来自supertom.com的使用PHP Stomp:http://www.supertom.com/code/activemq-php-stomp-quickstart.html (WebArchive)的快速入门指南。
在创建new Stomp()时,您需要传递一个TCP socket URL。我猜你的URL看起来是一个HTTP URL。例如,如果你连接到ActiveMQ,那么默认的网址是tcp://localhost:61613。
所以你的第二行代码应该是
$con = new Stomp("tcp://localhost:61613");
https://stackoverflow.com/questions/25206656
复制相似问题