本文整理汇总了Java中io.netty.handler.codec.http.websocketx.TextWebSocketFrame.text方法的典型用法代码示例。如果您正苦于以下问题:Java TextWebSocketFrame.text方法的具体用法?Java TextWebSocketFrame.text怎么用?Java TextWebSocketFrame.text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.http.websocketx.TextWebSocketFrame
的用法示例。
在下文中一共展示了TextWebSocketFrame.text方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receivedTextWebSocketFrame
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
void receivedTextWebSocketFrame(TextWebSocketFrame textWebSocketFrame) {
try {
Object deserializedMessage = webSocketMessageSerializer.deserialize(textWebSocketFrame.text());
if (deserializedMessage instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) deserializedMessage;
String firstHeader = httpResponse.getFirstHeader(WEB_SOCKET_CORRELATION_ID_HEADER_NAME);
WebSocketResponseCallback webSocketResponseCallback = callbackResponseRegistry.get(firstHeader);
if (webSocketResponseCallback != null) {
webSocketResponseCallback.handle(httpResponse);
}
} else if (deserializedMessage instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) deserializedMessage;
WebSocketRequestCallback webSocketRequestCallback = callbackForwardRegistry.get(httpRequest.getFirstHeader(WEB_SOCKET_CORRELATION_ID_HEADER_NAME));
if (webSocketRequestCallback != null) {
webSocketRequestCallback.handle(httpRequest);
}
} else {
throw new WebSocketException("Unsupported web socket message " + deserializedMessage);
}
} catch (Exception e) {
throw new WebSocketException("Exception while receiving web socket message" + textWebSocketFrame.text(), e);
}
}
示例2: channelRead0
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext arg0, TextWebSocketFrame in) throws Exception {
if( logger.isDebugEnabled() ) {
logger.debug("[CHANNEL READ0] channel active=" + arg0.channel().isActive() + ", open=" + arg0.channel().isOpen());
}
final String cm = in.text();
Platform.runLater( () -> receivingMessageModel.set(cm) );
}
示例3: decode
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, TextWebSocketFrame msg, List<Object> out) throws Exception {
String json = msg.text();
if (DEBUG) {
System.out.println(json);
}
try {
out.add(messageReader.readValue(json));
} catch (IllegalArgumentException e) {
// TODO just warn if decoded type is not implement yet
ctx.fireExceptionCaught(e);
}
}
示例4: channelRead0
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
logger.debug("WebSocket Client connected!");
handshakeFuture.setSuccess();
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException(
"Unexpected FullHttpResponse (getStatus=" + response.status() +
", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
logger.debug("WebSocket Client received text message: " + textFrame.text());
textReceived = textFrame.text();
} else if (frame instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame;
bufferReceived = binaryFrame.content().nioBuffer();
logger.debug("WebSocket Client received binary message: " + bufferReceived.toString());
} else if (frame instanceof PongWebSocketFrame) {
logger.debug("WebSocket Client received pong");
PongWebSocketFrame pongFrame = (PongWebSocketFrame) frame;
bufferReceived = pongFrame.content().nioBuffer();
} else if (frame instanceof CloseWebSocketFrame) {
logger.debug("WebSocket Client received closing");
ch.close();
}
}
示例5: notifyTextMessage
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
private void notifyTextMessage(TextWebSocketFrame textWebSocketFrame) throws ServerConnectorException {
String text = textWebSocketFrame.text();
boolean isFinalFragment = textWebSocketFrame.isFinalFragment();
WebSocketMessageImpl webSocketTextMessage =
new WebSocketTextMessageImpl(text, isFinalFragment);
webSocketTextMessage = setupCommonProperties(webSocketTextMessage);
connectorFuture.notifyWSListener((WebSocketTextMessage) webSocketTextMessage);
}
示例6: notifyTextMessage
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
private void notifyTextMessage(TextWebSocketFrame textWebSocketFrame, ChannelHandlerContext ctx)
throws ServerConnectorException {
String text = textWebSocketFrame.text();
boolean isFinalFragment = textWebSocketFrame.isFinalFragment();
WebSocketMessageImpl webSocketTextMessage =
new WebSocketTextMessageImpl(text, isFinalFragment);
webSocketTextMessage = setupCommonProperties(webSocketTextMessage, ctx);
connectorListener.onMessage((WebSocketTextMessage) webSocketTextMessage);
}
示例7: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
// Check for closing frame
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return;
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
return;
}
if (!(frame instanceof TextWebSocketFrame)) {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
.getName()));
}
// Send the uppercase string back.
TextWebSocketFrame frame2 = (TextWebSocketFrame) frame;
String request = frame2.text();
Thread t = Thread.currentThread();
System.err.printf("%s received %s%n thread %d ", ctx.channel(), request, t.getId());
///////////////////
//Do your work here
///////////////////
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
}
示例8: channelRead0
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
if (logger.isDebugEnabled()) {
logger.debug("WebSocket Client connected!");
}
handshakeFuture.setSuccess();
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException(
"Unexpected FullHttpResponse (getStatus=" + response.status() +
", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
if (logger.isDebugEnabled()) {
logger.debug("WebSocket Client received text message: " + textFrame.text());
}
textReceived = textFrame.text();
} else if (frame instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame;
bufferReceived = binaryFrame.content().nioBuffer();
if (logger.isDebugEnabled()) {
logger.debug("WebSocket Client received binary message: " + bufferReceived.toString());
}
} else if (frame instanceof PongWebSocketFrame) {
if (logger.isDebugEnabled()) {
logger.debug("WebSocket Client received pong");
}
PongWebSocketFrame pongFrame = (PongWebSocketFrame) frame;
bufferReceived = pongFrame.content().nioBuffer();
} else if (frame instanceof CloseWebSocketFrame) {
if (logger.isDebugEnabled()) {
logger.debug("WebSocket Client received closing");
}
isOpen = false;
}
countDownLatch();
}
示例9: channelRead0
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
logger.debug("WebSocket Client connected!");
handshakeFuture.setSuccess();
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException(
"Unexpected FullHttpResponse (getStatus=" + response.status() +
", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
logger.debug("WebSocket Client received text message: " + textFrame.text());
textReceived = textFrame.text();
} else if (frame instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame;
bufferReceived = binaryFrame.content().nioBuffer();
logger.debug("WebSocket Client received binary message: " + bufferReceived.toString());
} else if (frame instanceof PingWebSocketFrame) {
logger.debug("WebSocket Client received pong");
PingWebSocketFrame pingFrame = (PingWebSocketFrame) frame;
isPingReceived = true;
bufferReceived = pingFrame.content().nioBuffer();
} else if (frame instanceof PongWebSocketFrame) {
logger.debug("WebSocket Client received pong");
PongWebSocketFrame pongFrame = (PongWebSocketFrame) frame;
isPongReceived = true;
bufferReceived = pongFrame.content().nioBuffer();
} else if (frame instanceof CloseWebSocketFrame) {
logger.debug("WebSocket Client received closing");
isOpen = false;
}
countDownLatch();
}
示例10: channelRead0
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception {
String request = frame.text();
ctx.channel().writeAndFlush(new TextWebSocketFrame(request.toUpperCase()));
}
示例11: messageReceived
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入方法依赖的package包/类
@Override
protected void messageReceived(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception {
String request = frame.text();
ctx.channel().writeAndFlush(new TextWebSocketFrame(request.toUpperCase()));
}