Examples of TextWebSocketFrame


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

    public void invalidJsonInWebSocketFrame() throws Exception {
        final SockJsConfig config = SockJsConfig.withPrefix("/echo").build();
        final EmbeddedChannel ch = webSocketChannel(config);
        assertUpgradeRequest(ch);

        ch.writeInbound(new TextWebSocketFrame("[invalidJson"));
        assertThat(ch.isOpen(), is(false));
    }
View Full Code Here

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

    public void writeJsonArray() throws Exception {
        final SockJsConfig config = SockJsConfig.withPrefix("/echo").build();
        final EmbeddedChannel ch = webSocketChannel(config);
        assertUpgradeRequest(ch);

        ch.writeInbound(new TextWebSocketFrame("[\"x\",\"y\"]"));
        // Discard of the HttpRequest
        ch.readInbound();
        final String x = ch.readInbound();
        assertThat(x, equalTo("x"));
        final String y = ch.readInbound();
View Full Code Here

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

    public void writeJsonString() throws Exception {
        final SockJsConfig config = SockJsConfig.withPrefix("/echo").build();
        final EmbeddedChannel ch = webSocketChannel(config);
        assertUpgradeRequest(ch);

        ch.writeInbound(new TextWebSocketFrame("\"x\""));
        // Discard of the HttpRequest
        ch.readInbound();
        final String message = ch.readInbound();
        assertThat(message, equalTo("x"));
    }
View Full Code Here

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

    @Test
    public void messageReceived() throws Exception {
        final EmbeddedChannel ch = createWebsocketChannel(SockJsConfig.withPrefix("/echo").build());
        ch.writeOutbound(new MessageFrame("testing"));
        final TextWebSocketFrame textFrame = ch.readOutbound();
        assertThat(textFrame.content().toString(CharsetUtil.UTF_8), equalTo("a[\"testing\"]"));
        textFrame.release();
    }
View Full Code Here

Examples of org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame

        logger.trace("WebSocket.write()");

        if (binaryWrite) {
            channel.write(new BinaryWebSocketFrame(ChannelBuffers.wrappedBuffer(data.getBytes("UTF-8"))));
        } else {
            channel.write(new TextWebSocketFrame(data));
        }
        lastWrite = System.currentTimeMillis();
        return this;
    }
View Full Code Here

Examples of org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame

        if (!channel.isOpen()) throw new IOException("Connection remotely closed");

        if (binaryWrite) {
            channel.write(new BinaryWebSocketFrame(ChannelBuffers.wrappedBuffer(data, offset, length)));
        } else {
            channel.write(new TextWebSocketFrame(ChannelBuffers.wrappedBuffer(data, offset, length)));
        }
        lastWrite = System.currentTimeMillis();
    }
View Full Code Here

Examples of org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame

    Object message = ((MessageEvent)e).getMessage();
    if(!(message instanceof JSONObject) && !(message instanceof CharSequence)) {
            ctx.sendDownstream(e);
            return;     
    }
    WebSocketFrame frame = new TextWebSocketFrame(message.toString());   
    ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), frame, channel.getRemoteAddress()));   

  }
View Full Code Here

Examples of org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame

        }

        // Send the uppercase string back.
        String request = ((TextWebSocketFrame) frame).getText();
        log.info(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
        ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
   
  }
View Full Code Here

Examples of org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame

    Object value = cache.get(key);
   
    JSONObject responseObject = toJSON(key, value, cache.getName());
   
    // Write the JSON response out onto the channel...
    ctx.getChannel().write(new TextWebSocketFrame(responseObject.toString()));
  }
View Full Code Here

Examples of org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame

    String jsonString = jsonObject.toString();
    for(ChannelNotifyParams channel : channels) {
      if(channel.channel.isOpen() && channel.onEvents.contains(eventType)) {
        if(channel.key != null) {
          if(event.getKey().equals(channel.key) || channel.key.equals("*")) {
            channel.channel.write(new TextWebSocketFrame(jsonString));
          }
        } else {         
          channel.channel.write(new TextWebSocketFrame(jsonString));
        }
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.