【发布时间】:2017-08-19 01:28:21
【问题描述】:
我一直在尝试使用 cometd 版本 3.1.2 和 jetty 9.4.6.v20170531 以及 cometd 文档中的代码来设置一个非常简单的 cometd java 服务器和客户端。
HttpClient httpClient = new HttpClient();
httpClient.start();
Map<String, Object> options = new HashMap<String, Object>();
ClientTransport transport = new LongPollingTransport(options, httpClient);
BayeuxClient client = new BayeuxClient("http://localhost:9025/mycontext/cometd/", transport);
client.handshake();
boolean handshaken = client.waitFor(5000, BayeuxClient.State.CONNECTED);
if (handshaken) {
System.out.println("Yes");
// Here handshake is successful
}
System.out.println("Done");
服务器设置是我真正感兴趣的,它是一个带有 cometd servlet 的弹簧注入嵌入式码头服务器。无论我尝试过什么,客户都不会握手。我终于能够通过邮递员发送此请求来证明服务器设置正确且可用...
发布http://localhost:9025/mycontext/cometd
[{
"version": "1.0",
"minimumVersion": "0.9",
"channel": "/meta/handshake",
"supportedConnectionTypes": [
"long-polling",
"callback-polling"
],
"advice": {
"timeout": 60000,
"interval": 0
},
"id": "1"
}]
...返回 200...
[
{
"minimumVersion": "1.0",
"clientId": "11jlmrekgqnu9v1i4w1b8rgiq3c",
"supportedConnectionTypes": [
"long-polling",
"websocket"
],
"advice": {
"interval": 0,
"timeout": 60000,
"reconnect": "retry"
},
"channel": "/meta/handshake",
"id": "1",
"version": "1.0",
"successful": true
}
]
...所以,很明显,服务器设置很好。我已经设置了断点并使用 tcpflow 来查找流量,据我所知,使用 cometd 自己的库的最简单的客户端从他们的入门文档中根本不会发送任何请求。没有 tcp 流量。有人知道我错过了什么吗?任何帮助表示赞赏。
【问题讨论】:
-
"无论我怎么尝试,客户端都不会握手。"它是否抛出了特定的错误?