Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] WebSockets: Specific Client Message


According to jetty Web application architecture,

ServletHandler is located in the lastest.. 

So, I tried to adapt DefaultHandler to WebSocketHandler... but it didn't work..

I don't know why...

Is really there no way except Servlet for WebSocket..?

This is my source..


public class PocWebSocketServletContextListener implements ServletContextListener{

    private Server server;
    public void contextDestroyed(ServletContextEvent arg0) {
        if (server != null) {
            try {
                // stop the Jetty server.
            } catch (Exception e) {

    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("PocWebSocketServletContextListener has received a servlet context event.");
            this.server = new Server(8081);

            PocWebSocketHandler handler = new PocWebSocketHandler();
            handler.setHandler(new org.eclipse.jetty.server.handler.DefaultHandler());

        }catch(Throwable e){
public class PocWebSocketHandler extends WebSocketHandler{

    public PocWebSocketHandler(){
        System.out.println("PocWebSocketHandler is created.");
    public WebSocket doWebSocketConnect(HttpServletRequest arg0, String arg1) {
        return new PocWebSocket();

Thanks in advance.


On Wed, Jan 11, 2012 at 4:35 AM, Simone Bordet <sbordet@xxxxxxxxxxx> wrote:

On Tue, Jan 10, 2012 at 20:25, Hendrik Schenk <hschenk@xxxxxxx> wrote:
> stupid of me!
> So it was correct what i did. thank you for your help.
> And a servlet is the correct way to use websockets in jetty? or is there
> another way?

WebSocketServlet is the best way.

Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz
jetty-users mailing list


Seonhong Ahn
Director of Research and Development

Collabra Co.
960-6 Deachi-dong, Gangnam-gu, Seoul, Korea 135-280 
Tel. 82-70-8670-6929         Fax. 82-2-6280-4807
Mobile 82-10-8292-3923

Back to the top