Package io.netty.handler.codec.http.websocketx

Examples of io.netty.handler.codec.http.websocketx.TextWebSocketFrame


                    + response.data().toString(CharsetUtil.UTF_8) + ')');
        }

        WebSocketFrame frame = (WebSocketFrame) msg;
        if (frame instanceof TextWebSocketFrame) {
            TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
            System.out.println("WebSocket Client received message: " + textFrame.text());
        } else if (frame instanceof PongWebSocketFrame) {
            System.out.println("WebSocket Client received pong");
        } else if (frame instanceof CloseWebSocketFrame) {
            System.out.println("WebSocket Client received closing");
            ch.close();
View Full Code Here


public class CustomTextFrameHandler extends ChannelInboundMessageHandlerAdapter<TextWebSocketFrame> {

    @Override
    public void messageReceived(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception {
        String request = frame.text();
        ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
    }
View Full Code Here

        // Send the uppercase string back.
        String request = ((TextWebSocketFrame) frame).text();
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
        }
        ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
    }
View Full Code Here

public class WebSocketClientServerTest {

    @Test
    public void testTextCommunication() throws Exception {
        TestSequenceExecutor executor = new TestSequenceExecutor()
                .withClientFrames(new TextWebSocketFrame("clientRequest"))
                .withExpectedOnServer(1)
                .withServerFrames(new TextWebSocketFrame("serverResponse"))
                .withExpectedOnClient(1)
                .execute();

        assertEquals("Expected original client request", "clientRequest", asText(executor.getReceivedClientFrames().get(0)));
        assertEquals("Expected original server response", "serverResponse", asText(executor.getReceivedServerFrames().get(0)));
View Full Code Here

    @Test
    public void testFragmentedMessage() throws Exception {
        TestSequenceExecutor executor = new TestSequenceExecutor()
                .withClientFrames(
                        new TextWebSocketFrame(false, 0, "first"),
                        new ContinuationWebSocketFrame(false, 0, "middle"),
                        new ContinuationWebSocketFrame(true, 0, "last")
                )
                .withExpectedOnServer(3)
                .execute();
View Full Code Here

    @Test
    public void testMessageAggregationOnServer() throws Exception {
        TestSequenceExecutor executor = new TestSequenceExecutor()
                .withMessageAggregation(true)
                .withClientFrames(new TextWebSocketFrame(false, 0, "0123456789"), new ContinuationWebSocketFrame(true, 0, "ABCDEFGHIJ"))
                .withExpectedOnServer(1)
                .execute();
        assertEquals("Expected aggregated message", "0123456789ABCDEFGHIJ", asText(executor.getReceivedClientFrames().get(0)));
    }
View Full Code Here

    @Test
    public void testMessageAggregationOnClient() throws Exception {
        TestSequenceExecutor executor = new TestSequenceExecutor()
                .withMessageAggregation(true)
                .withServerFrames(new TextWebSocketFrame(false, 0, "0123456789"), new ContinuationWebSocketFrame(true, 0, "ABCDEFGHIJ"))
                .withExpectedOnClient(1)
                .execute();
        assertEquals("Expected aggregated message", "0123456789ABCDEFGHIJ", asText(executor.getReceivedServerFrames().get(0)));
    }
View Full Code Here

            @Override
            public Observable<Void> handle(final ObservableConnection<WebSocketFrame, WebSocketFrame> connection) {
                return connection.getInput().flatMap(new Func1<WebSocketFrame, Observable<Void>>() {
                    @Override
                    public Observable<Void> call(WebSocketFrame webSocketFrame) {
                        return connection.writeAndFlush(new TextWebSocketFrame("WS-Reply"));
                    }
                });
            }
        }).build();
        server.subscribe(serverEventListener);
View Full Code Here

        client.connect().flatMap(new Func1<ObservableConnection<WebSocketFrame, WebSocketFrame>, Observable<Void>>() {
            @Override
            public Observable<Void> call(final ObservableConnection<WebSocketFrame, WebSocketFrame> connection) {
                return Observable.concat(
                        connection.writeAndFlush(new TextWebSocketFrame("WS-Request")),
                        connection.getInput().flatMap(new Func1<WebSocketFrame, Observable<Void>>() {
                            @Override
                            public Observable<Void> call(WebSocketFrame webSocketFrame) {
                                return connection.close();
                            }
View Full Code Here

        Notification<Void> result = rxClient.connect()
                .flatMap(new Func1<ObservableConnection<TextWebSocketFrame, TextWebSocketFrame>, Observable<Void>>() {
                    @Override
                    public Observable<Void> call(final ObservableConnection<TextWebSocketFrame, TextWebSocketFrame> connection) {
                        return Observable.concat(
                                connection.writeAndFlush(new TextWebSocketFrame("Hello!!!")),
                                connection.getInput().take(noOfEvents).flatMap(new Func1<TextWebSocketFrame, Observable<Void>>() {
                                    @Override
                                    public Observable<Void> call(TextWebSocketFrame webSocketFrame) {
                                        System.out.println("Got back: " + webSocketFrame.text());
                                        return Observable.timer(interval, TimeUnit.MILLISECONDS)
                                                .flatMap(new Func1<Long, Observable<Void>>() {
                                                    @Override
                                                    public Observable<Void> call(Long aLong) {
                                                        return connection.writeAndFlush(new TextWebSocketFrame("Hello!!!"));
                                                    }
                                                });
                                    }
                                }));
                    }
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.http.websocketx.TextWebSocketFrame

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.