[英]Connect with a Stomp PHP library to Spring websockets (stomp)
我已经编译并运行了本指南中的代码:
http://spring.io/guides/gs/messaging-stomp-websocket/
我想使用此 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循环中尝试接收来自服务器的响应,该文件位于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
我做错了什么?
这是来自supertom.com的使用PHP Stomp的快速入门指南: http : //www.supertom.com/code/activemq-php-stomp-quickstart.html (WebArchive)。
创建new Stomp()
,需要传递一个TCP套接字URL。 我猜您的网址看起来是HTTP URL。 例如,如果您要连接到ActiveMQ,则默认URL为tcp://localhost:61613
。
所以你的第二行代码是
$con = new Stomp("tcp://localhost:61613");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.