我遵循了用户指南提供的这里:我在我的pom中添加了以下内容:
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-server</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly</artifactId>
<version>1.2</version>
</dependency>我在主修课上写了这个:
Server server = new Server("localhost", 8624, "/", EchoEndPoint.class);
try
{
server.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please press a key to stop the server.");
reader.readLine();
}
catch(Exception ex) { ex.printStackTrace(); }
finally
{
server.stop();
}我的EchoEndPoint类的内容与描述的在指南中相同。
我尝试用HTML5 websocket连接到此:
var ws = new WebSocket("ws://localhost:8624/echo");浏览器端似乎没有连接(它直接调用onClose回调)。服务器端,我在控制台中得到了这样的信息:
Grave: Invalid Connection header returned: 'keep-alive'
org.glassfish.tyrus.websockets.HandshakeException: Invalid Connection header returned: 'keep-alive'
at org.glassfish.tyrus.websockets.HandShake.validate(HandShake.java:254)
at org.glassfish.tyrus.websockets.HandShake.checkForHeader(HandShake.java:246)
at org.glassfish.tyrus.websockets.HandShake.<init>(HandShake.java:97)
at org.glassfish.tyrus.websockets.draft06.HandShake06.<init>(HandShake06.java:63)
[...]
org.glassfish.grizzly.filterchain.DefaultFilterChain execute
Avertissement: Exception during FilterChain execution
java.lang.ClassCastException: org.glassfish.grizzly.http.HttpContent cannot be cast to org.glassfish.tyrus.websockets.DataFrame
at org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleWrite(WebSocketFilter.java:330)如果有任何帮助,我将复制浏览器检查器捕获的请求头:
GET /echo HTTP/1.1
Host: localhost:8624
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0 FirePHP/0.7.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Sec-WebSocket-Version: 13
Origin: null
Sec-WebSocket-Key: yhGPwJ26c5fYEZ5/abvtqw==
x-insight: activate
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket这是握手问题吗?
编辑:我试过在Chrome上使用 (28.0.1500.72),它正在工作。也许这个问题来自火狐,当它构建标题?
发布于 2013-07-31 19:37:10
Tyrus在抱怨Connection: keep-alive, Upgrade的标题。
火狐在这里没有做错任何事情。
Tyrus在如何处理连接标头方面受到了太大的限制,没有遵循WebSocket规范(RFC-6455)。
第4.1节中的RFC状态
6. The request MUST contain a |Connection| header field whose value
MUST include the "Upgrade" token.和
3. If the response lacks a |Connection| header field or the
|Connection| header field doesn't contain a token that is an
ASCII case-insensitive match for the value "Upgrade", the client
MUST _Fail the WebSocket Connection_.这好像是泰勒斯的窃听器。
https://stackoverflow.com/questions/17943743
复制相似问题