简体   繁体   English

tomcat 8 javax.websockets不起作用

[英]tomcat 8 javax.websockets doesn't work

I have tomcat 8-RC1 installed in order to use javax.websockets to write websocket based applications. 我安装了tomcat 8-RC1,以便使用javax.websockets编写基于websocket的应用程序。

there are examples at http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/ that show exactly the structure of a websocket class so I implemented the following interface: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/上有一些示例,它们准确显示了websocket类的结构,因此我实现了以下接口:

public interface XpoWebSocket {

@OnOpen
public void onOpen(Session session);

@OnClose
public void onClose();

@OnMessage
public void onTextMessage(String message);

public Session getSession();

}

in the line above the class deceleration I also included the following: 在班级减速的上面我还包括以下内容:

@ServerEndpoint(value = "/ServConnect")
public class ServConnect implements XpoWebSocket {
...

so the ServerEndPoint is to point how to access to websocket, the question is what do i need to set in web.xml ? 所以ServerEndPoint是指向如何访问websocket,问题是我需要在web.xml中设置什么? for now the web socket is still not accessible. 目前仍无法访问Web套接字。

I try to define ServConnect as a regular Servlet in web.xml but that doesn't work. 我尝试将ServConnect定义为web.xml中的常规Servlet,但这不起作用。 it just time out when I try to access the ServConnect location. 它只是在我尝试访问ServConnect位置时超时。

what configuration am I missing to let this ServConnect websocket class work ? 我想让这个ServConnect websocket类工作的配置是什么?

The WebSocket spec says that you have to annotate the concrete class. WebSocket规范说你必须注释具体类。 ServConnect will be treated as a WebSocket endpoint but will not receive any events as the annotations on the interface are ignored. ServConnect将被视为WebSocket端点,但不会接收任何事件,因为忽略了接口上的注释。

I'd suggest getting your own version of the Echo example working and then expanding from there. 我建议让你自己的Echo示例版本工作,然后从那里扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM