在Tomcat 6中使用websockets



有没有办法在tomcat 6中使用websockets(业务需求)?

我一直在尝试使用 javax.websocket.jar但我无法让它工作

这是我的代码:

import java.io.IOException;
import java.nio.ByteBuffer;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/echoAnnotation")
public class EchoAnnotation {    @OnMessage
     public void echoTextMessage(Session session, String msg, boolean last) {
          try {
               if (session.isOpen()) {
                    session.getBasicRemote().sendText(msg, last);
               }
          } catch (IOException e) {
               try {
                    session.close();
               } catch (IOException e1) {
                    // Ignore
               }
          }
     }
}

还有我的网络.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5"> 
    <description>
      Servlet and JSP Examples.
    </description>
    <display-name>Servlet and JSP Examples</display-name>
    <servlet>
        <servlet-name>echoAnnotation</servlet-name>
        <servlet-class>EchoAnnotation</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>echoAnnotation</servlet-name>
        <url-pattern>/echoAnnotation</url-pattern>
    </servlet-mapping>
</web-app>

但是我无法建立 websocket 连接,我收到一条错误消息Firefox can't establish a connection to the server at ws://192.168.1.101:8080/prototypes/echoAnnotation并直接转到页面会导致HTTP Status 404 - Servlet echoAnnotation is not available

这可能吗?我做错了什么?

正如我发现tomcat 6不支持Java WebSockets。见 http://tomcat.apache.org/whichversion.html

相关内容

  • 没有找到相关文章

最新更新