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


Java PongWebSocketFrame類代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.websocketx.PongWebSocketFrame的典型用法代碼示例。如果您正苦於以下問題:Java PongWebSocketFrame類的具體用法?Java PongWebSocketFrame怎麽用?Java PongWebSocketFrame使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PongWebSocketFrame類屬於io.netty.handler.codec.http.websocketx包,在下文中一共展示了PongWebSocketFrame類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
    if (logger.isLoggable(Level.FINE)) {
        logger.fine(String.format(
                "Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame)));
    }

    if (frame instanceof CloseWebSocketFrame) {
        handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
    } else if (frame instanceof PingWebSocketFrame) {
        ctx.write(new PongWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.content()), ctx.voidPromise());
    } else if (frame instanceof TextWebSocketFrame) {
        ctx.write(frame, ctx.voidPromise());
    } else if (frame instanceof BinaryWebSocketFrame) {
        ctx.write(frame, ctx.voidPromise());
    } else if (frame instanceof ContinuationWebSocketFrame) {
        ctx.write(frame, ctx.voidPromise());
    } else if (frame instanceof PongWebSocketFrame) {
        frame.release();
        // Ignore
    } else {
        throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
                .getName()));
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:25,代碼來源:AutobahnServerHandler.java

示例2: handlerWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
private void handlerWebSocketFrame(ChannelHandlerContext ctx,
		WebSocketFrame frame) {
	// 判斷是否關閉鏈路的指令
	if (frame instanceof CloseWebSocketFrame) {
		socketServerHandshaker.close(ctx.channel(),
				(CloseWebSocketFrame) frame.retain());
	}
	// 判斷是否ping消息
	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()));
	}
	// 返回應答消息
	String request = ((TextWebSocketFrame) frame).text();
	System.out.println("服務端收到:" + request);
	TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString()
			+ ctx.channel().id() + ":" + request);
	// 群發
	group.writeAndFlush(tws);
}
 
開發者ID:hdcuican,項目名稱:java_learn,代碼行數:27,代碼來源:WebSocketServerHandler.java

示例3: handleFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
private void handleFrame(Channel channel, WebSocketFrame frame, WebSocketUpgradeHandler handler, NettyWebSocket webSocket) throws Exception {
    if (frame instanceof CloseWebSocketFrame) {
        Channels.setDiscard(channel);
        CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
        webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText());
    } else {
        ByteBuf buf = frame.content();
        if (buf != null && buf.readableBytes() > 0) {
            HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment());
            handler.onBodyPartReceived(part);

            if (frame instanceof BinaryWebSocketFrame) {
                webSocket.onBinaryFragment(part);
            } else if (frame instanceof TextWebSocketFrame) {
                webSocket.onTextFragment(part);
            } else if (frame instanceof PingWebSocketFrame) {
                webSocket.onPing(part);
            } else if (frame instanceof PongWebSocketFrame) {
                webSocket.onPong(part);
            }
        }
    }
}
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:24,代碼來源:WebSocketHandler.java

示例4: onInboundNext

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
@Override
public void onInboundNext(ChannelHandlerContext ctx, Object frame) {
	if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) {
		if (log.isDebugEnabled()) {
			log.debug("CloseWebSocketFrame detected. Closing Websocket");
		}
		CloseWebSocketFrame close = (CloseWebSocketFrame) frame;
		sendClose(new CloseWebSocketFrame(true,
				close.rsv(),
				close.content()), f -> onHandlerTerminate());
		return;
	}
	if (frame instanceof PingWebSocketFrame) {
		ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content()));
		ctx.read();
		return;
	}
	super.onInboundNext(ctx, frame);
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:20,代碼來源:HttpServerWSOperations.java

示例5: decodeWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
private Message decodeWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
	// Check for closing frame
	if (frame instanceof CloseWebSocketFrame) {
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		return null;
	}
	
	if (frame instanceof PingWebSocketFrame) {
		ctx.write(new PongWebSocketFrame(frame.content().retain()));
		return null;
	}
	
	if (frame instanceof TextWebSocketFrame) {
		TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
		return parseMessage(textFrame.content());
	}
	
	if (frame instanceof BinaryWebSocketFrame) {
		BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) frame;
		return parseMessage(binFrame.content());
	}
	
	log.warn("Message format error: " + frame); 
	return null;
}
 
開發者ID:rushmore,項目名稱:zbus,代碼行數:26,代碼來源:MessageCodec.java

示例6: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的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.write(new PongWebSocketFrame(frame.content().retain()));
            return;
        }
        if (frame instanceof TextWebSocketFrame) {
            // Echo the frame
            ctx.write(frame.retain());
            return;
        }
        if (frame instanceof BinaryWebSocketFrame) {
            // Echo the frame
            ctx.write(frame.retain());
            return;
        }
    }
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:23,代碼來源:WebSocketServerHandler.java

示例7: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
	// Check for closing frame
	if (frame instanceof CloseWebSocketFrame) {
		addTraceForFrame(frame, "close");
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		return;
	}
	if (frame instanceof PingWebSocketFrame) {
		addTraceForFrame(frame, "ping");
		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()));
	}

	// todo [om] think about BinaryWebsocketFrame

	handleTextWebSocketFrameInternal((TextWebSocketFrame) frame, ctx);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:22,代碼來源:WebsocketSinkServerHandler.java

示例8: channelRead0

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext context, Object message) throws Exception {
	final Channel channel = context.channel();
	if (!handshaker.isHandshakeComplete()) {
		handshaker.finishHandshake(channel, (FullHttpResponse) message);
		channel.pipeline().addBefore(HANDLER_NAME, "websocket-frame-aggregator", new WebSocketFrameAggregator(64 * 1024));
		subscriber.onStart();
		return;
	}

	if (message instanceof FullHttpResponse) {
		final FullHttpResponse response = (FullHttpResponse) message;
		throw new IllegalStateException(
				"Unexpected FullHttpResponse (getStatus=" + response.getStatus() +
						", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
	}

	final WebSocketFrame frame = (WebSocketFrame) message;
	if (frame instanceof PingWebSocketFrame) {
		context.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame)frame).retain().content()));
	} else if (frame instanceof BinaryWebSocketFrame) {
		final ByteBufInputStream input = new ByteBufInputStream(((BinaryWebSocketFrame)message).content());
		final Envelope envelope = Envelope.ADAPTER.decode(input);
		subscriber.onNext(envelope);
	}
}
 
開發者ID:cloudfoundry-community,項目名稱:snotel,代碼行數:27,代碼來源:NettyFirehoseOnSubscribe.java

示例9: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的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.
        String request = ((TextWebSocketFrame) frame).text();
        System.err.printf("%s received %s%n", ctx.channel(), request);
        ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
    }
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:22,代碼來源:WebSocketServerHandler.java

示例10: accept

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
@Override
public void accept(ChannelHandlerContext ctx, WebSocketFrame frame) {
	if (frame instanceof CloseWebSocketFrame) {
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		endpoint.releaseReferences();
		endpoint.onClose();
		return;
	}
	
	if (frame instanceof PingWebSocketFrame) {
		ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
		return;
	}
	
	if (frame instanceof TextWebSocketFrame) {
		endpoint.onMessage(((TextWebSocketFrame) frame).text());
		return;
	}
	
	throw new UnsupportedOperationException(String.format("Unsupported websocket frame of type %s", frame.getClass().getName()));
}
 
開發者ID:lukasdietrich,項目名稱:lambdatra,代碼行數:22,代碼來源:WsAdapter.java

示例11: handlerWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
private void handlerWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
	// 判斷是否關閉鏈路的指令
	if (frame instanceof CloseWebSocketFrame) {
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		return;
	}
	// 判斷是否ping消息
	if (frame instanceof PingWebSocketFrame) {
		ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
		return;
	}
	// 僅支持文本消息,不支持二進製消息
	if (!(frame instanceof TextWebSocketFrame)) {
		ctx.close();//(String.format("%s frame types not supported", frame.getClass().getName()));
		return;
	}

}
 
開發者ID:brenthub,項目名稱:brent-pusher,代碼行數:19,代碼來源:NettyPusherServer.java

示例12: handle

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
public void handle(ChannelHandlerContext ctx, WebSocketFrame frame) {
    if (frame instanceof CloseWebSocketFrame) {
        handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
        onClose(ctx);
        return;
    }
    if (frame instanceof PingWebSocketFrame) {
        ctx.channel().write(new PongWebSocketFrame(frame.content()));
        return;
    }
    if (!(frame instanceof TextWebSocketFrame)) {
        throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
                .getName()));
    }

    String msg = ((TextWebSocketFrame) frame).text();
    onMessage(ctx, msg);
}
 
開發者ID:buremba,項目名稱:netty-rest,代碼行數:19,代碼來源:WebSocketService.java

示例13: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
public void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

		// 判斷是否是關閉鏈路的指令
		if (frame instanceof CloseWebSocketFrame) {
			handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
			return;
		}
		// 判斷是否是Ping消息
		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()));
		}
		//返回應答消息
		String request= ((TextWebSocketFrame)frame).text();
		System.out.println(String.format("%s received %s", ctx.channel(), request));
		
		ctx.channel().write(new TextWebSocketFrame(request+" ,現在時刻:"+new Date()));
		
	}
 
開發者ID:zoopaper,項目名稱:netty-study,代碼行數:24,代碼來源:WebSocketServerHandler.java

示例14: channelRead

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
        throws UnknownWebSocketFrameTypeException, ServerConnectorException {
    if (!(msg instanceof WebSocketFrame)) {
        logger.error("Expecting WebSocketFrame. Unknown type.");
        throw new UnknownWebSocketFrameTypeException("Expecting WebSocketFrame. Unknown type.");
    }
    if (msg instanceof TextWebSocketFrame) {
        notifyTextMessage((TextWebSocketFrame) msg);
    } else if (msg instanceof BinaryWebSocketFrame) {
        notifyBinaryMessage((BinaryWebSocketFrame) msg);
    } else if (msg instanceof CloseWebSocketFrame) {
        notifyCloseMessage((CloseWebSocketFrame) msg);
    } else if (msg instanceof PingWebSocketFrame) {
        notifyPingMessage((PingWebSocketFrame) msg);
    } else if (msg instanceof PongWebSocketFrame) {
        notifyPongMessage((PongWebSocketFrame) msg);
    }
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:20,代碼來源:WebSocketSourceHandler.java

示例15: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; //導入依賴的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.
        String request = ((TextWebSocketFrame) frame).text();
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(String.format("%s received %s", ctx.channel(), request));
        }
        ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
    }
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:24,代碼來源:WebSocketServerHandler.java


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