使用Stomp PHP库连接到Spring WebSocket(Stomp)

使用Stomp PHP库连接到Spring WebSocket(Stomp),php,spring,websocket,stomp,Php,Spring,Websocket,Stomp,我已经编译并运行了本指南中的代码: 我想使用Stomp PHP库连接到 在本地主机上的端口8080上启动 这是我运行以连接到Spring server的代码: <?php // include a library require_once("Stomp.php"); // make a connection $con = new Stomp("tcp://localhost:8080"); // connect $con->connect(); // send a message

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

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

这是我运行以连接到Spring server的代码:

<?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();

我做错了什么?

这里是supertom.com提供的关于使用PHP Stomp:WebArchive的快速入门指南

创建新Stomp时,需要传递TCP套接字URL。我猜您的URL看起来是一个HTTP URL。例如,如果您连接到ActiveMQ,则默认URL为tcp://localhost:61613.

所以你的第二行代码是

$con=新的tomptcp://localhost:61613;

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