首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tyrus websocket服务器握手问题?

Tyrus websocket服务器握手问题?
EN

Stack Overflow用户
提问于 2013-07-30 09:51:39
回答 1查看 2.4K关注 0票数 2

我遵循了用户指南提供的这里:我在我的pom中添加了以下内容:

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

我在主修课上写了这个:

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

代码语言:javascript
复制
var ws = new WebSocket("ws://localhost:8624/echo");

浏览器端似乎没有连接(它直接调用onClose回调)。服务器端,我在控制台中得到了这样的信息:

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

如果有任何帮助,我将复制浏览器检查器捕获的请求头:

代码语言:javascript
复制
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),它正在工作。也许这个问题来自火狐,当它构建标题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-31 19:37:10

Tyrus在抱怨Connection: keep-alive, Upgrade的标题。

火狐在这里没有做错任何事情。

Tyrus在如何处理连接标头方面受到了太大的限制,没有遵循WebSocket规范(RFC-6455)。

第4.1节中的RFC状态

代码语言:javascript
复制
   6.   The request MUST contain a |Connection| header field whose value
        MUST include the "Upgrade" token.

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

这好像是泰勒斯的窃听器。

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

https://stackoverflow.com/questions/17943743

复制
相关文章

相似问题

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