首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Stomp PHP库连接到Spring websockets (stomp)

使用Stomp PHP库连接到Spring websockets (stomp)
EN

Stack Overflow用户
提问于 2014-08-08 23:12:25
回答 1查看 1.3K关注 0票数 1

我已经编译并运行了本指南中的代码:

http://spring.io/guides/gs/messaging-stomp-websocket/

我想使用this Stomp PHP库连接到在本地主机端口8080上启动的服务器。

这是我用来连接Spring服务器的代码:

代码语言:javascript
复制
<?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中尝试接收帧。

接下来是来自服务器的响应:

代码语言:javascript
复制
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

我哪里做错了?

EN

回答 1

Stack Overflow用户

发布于 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");

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25206656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档