當前位置: 首頁>>代碼示例>>Java>>正文


Java TextWebSocketFrame.text方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:jamesdbloom,項目名稱:mockserver,代碼行數:24,代碼來源:WebSocketClientRegistry.java

示例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) );
}
 
開發者ID:bekwam,項目名稱:examples-javafx-repos1,代碼行數:11,代碼來源:EchoClientHandlerWS.java

示例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);
    }
}
 
開發者ID:h4ssi,項目名稱:mmo-client,代碼行數:16,代碼來源:ServerConnection.java

示例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();
    }
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:36,代碼來源:WebSocketClientHandler.java

示例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);
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:9,代碼來源:WebSocketSourceHandler.java

示例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);
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:10,代碼來源:WebSocketTargetHandler.java

示例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()));
        
    }
 
開發者ID:oci-pronghorn,項目名稱:NettyStages,代碼行數:36,代碼來源:WebSocketServerHandler.java

示例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();
}
 
開發者ID:wso2,項目名稱:product-ei,代碼行數:47,代碼來源:WebSocketClientHandler.java

示例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();
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:43,代碼來源:WebSocketClientHandler.java

示例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()));
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:6,代碼來源:CustomTextFrameHandler.java

示例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()));
}
 
開發者ID:nathanchen,項目名稱:netty-netty-5.0.0.Alpha1,代碼行數:6,代碼來源:CustomTextFrameHandler.java


注:本文中的io.netty.handler.codec.http.websocketx.TextWebSocketFrame.text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。