本文整理匯總了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()));
}