Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty 9 and WebSocket

Which version of Jetty 9.0.0?

--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
Developer advice, services and support
from the Jetty & CometD experts


On Mon, Mar 4, 2013 at 1:07 PM, Alex <aleksgab@xxxxxxxxx> wrote:
Hi,

I have a very basic question.

I managed to write a HttpServer with Jetty8. Now I am trying to write a WebSocket with Jetty 9. I followed the tutorial for creating a WebSocket-Server using WebSocketServlet and WebSocketAdapter. But when I do the echo-Test with websocket.org/echo.html, I don't get the response,only CONNECTED and SENT: message.  What do I need add to my classes, so that it works?

Thanks for your help

Alex

My classes are:

public class MyWebSocketServlet extends WebSocketServlet {
    public void configure(WebSocketServletFactory factory) {
         factory.register(MyWebSocket.class);
    }
}

public class MyWebSocket  extends WebSocketAdapter{
    public void onWebSocketText(String message) {
        if (isNotConnected()) {
           return; }
        try{
            this.session.getRemote().sendString("You sent: "+message);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
   
}

public class MyServer {
  public static void main(String[] args) throws Exception {  
      Server server = new Server(8050);
      ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
      server.setHandler(context);
      context.addServlet(new ServletHolder(new MyWebSocketServlet()),"/*");

      server.start();
      server.join();
  }
}
 



_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top