Package org.xlightweb

Examples of org.xlightweb.TextMessage


               
            }

           
            public void onMessage(IWebSocketConnection webStream) throws IOException {
                TextMessage msg = webStream.readTextMessage();
                if (msg.toString().equalsIgnoreCase("GetDate")) {
                    webStream.writeMessage(new TextMessage(new Date().toString()));
                } else {
                    webStream.writeMessage(new TextMessage("unknown command (supported: GetDate)"));
                }
            }
           
           
            public void onDisconnect(IWebSocketConnection webStream) throws IOException {
               
            }
        }

       
        HttpServer server = new HttpServer(8876, new ServerHandler());
        server.start();
       
       
        HttpClient httpClient = new HttpClient();

        httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/WebSocketsExample"));
       
        IWebSocketConnection wsCon = httpClient.openWebSocketConnection("ws://localhost:" + server.getLocalPort() + "/WebSocketsExample", "mySubprotocol");
       
        wsCon.writeMessage(new TextMessage("GetDate"));
        TextMessage msg = wsCon.readTextMessage();
       
       
       
        httpClient.close();
       
View Full Code Here


               
            }

           
            public void onMessage(IWebSocketConnection webStream) throws IOException {
                TextMessage msg = webStream.readTextMessage();
                if (msg.toString().equalsIgnoreCase("GetDate")) {
                    webStream.writeMessage(new TextMessage(new Date().toString()));
                } else {
                    webStream.writeMessage(new TextMessage("unknown command (supported: GetDate)"));
                }
            }
View Full Code Here

            }
           
           
            // IWebSocketHandler
            public void onMessage(IWebSocketConnection webStream) throws IOException {
                TextMessage msg = webStream.readTextMessage();
                if (msg.toString().equalsIgnoreCase("GetDate")) {
                   webStream.writeMessage(new TextMessage(new Date().toString()));
                } else {
                    webStream.writeMessage(new TextMessage("unknown command (supported: GetDate)"));
                }
            }
           
            // IWebSocketHandler
            public void onDisconnect(IWebSocketConnection webStream) throws IOException {  }
View Full Code Here

            }
           
           
            // IWebSocketHandler
            public void onMessage(IWebSocketConnection webStream) throws IOException {
                TextMessage msg = webStream.readTextMessage();
                if (msg.toString().equalsIgnoreCase("GetDate")) {
                   webStream.writeMessage(new TextMessage(new Date().toString()));
                } else {
                    webStream.writeMessage(new TextMessage("unknown command (supported: GetDate)"));
                }
            }
View Full Code Here

        }

        public void onMessage(IWebSocketConnection webSocketConnection) throws IOException {
            String message = webSocketConnection.readTextMessage().toString();
            System.out.println("received ws message " + message);
            webSocketConnection.writeMessage(new TextMessage(message + " " + new Date().toString()));
        }
View Full Code Here

           
            public void onDisconnect(IWebSocketConnection con) throws IOException {
            }
           
            public void onMessage(IWebSocketConnection con) throws IOException {
                TextMessage msg = con.readTextMessage();
                con.writeMessage(msg);
            }
        };
       
        HttpServer server = new HttpServer(8877, echoHandler);
View Full Code Here

        /////////////////////////
        // with handler
        IWebSocketHandler handler = new IWebSocketHandler() {
           
            public void onMessage(IWebSocketConnection con) throws IOException {
                TextMessage msg = con.readTextMessage();
                System.out.println(msg);
            }
           
            public void onDisconnect(IWebSocketConnection con) throws IOException { }
           
            public void onConnect(IWebSocketConnection con) throws IOException, UnsupportedProtocolException {  }
        };
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" + port, "com.example.echo", handler);
       
        webSocketConnection.writeMessage(new TextMessage("0123456789"));

       
       
        ////////////////////////////////////////////
        // without handler 
        IWebSocketConnection webSocketConnection2 = httpClient.openWebSocketConnection("ws://localhost:" + port, "com.example.echo");
   
        webSocketConnection2.writeMessage(new TextMessage("0123456789"));
        TextMessage msg = webSocketConnection2.readTextMessage();
        Assert.assertEquals("0123456789", msg.toString());

        webSocketConnection2.writeMessage(new TextMessage("0123456789"));
        msg = webSocketConnection2.readTextMessage();
        Assert.assertEquals("0123456789", msg.toString());

        webSocketConnection.close();
        webSocketConnection2.close();
    }
View Full Code Here

TOP

Related Classes of org.xlightweb.TextMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.