Java Code Examples for io.netty.handler.codec.mqtt.MqttMessageType#PINGREQ
The following examples show how to use
io.netty.handler.codec.mqtt.MqttMessageType#PINGREQ .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MqttPingHandler.java From smartacus-mqtt-broker with Apache License 2.0 | 6 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof MqttMessage)) { System.out.println("=============收到非Mqtt==========="); ctx.fireChannelRead(msg); ctx.close(); return; } MqttMessage message = (MqttMessage) msg; if(message.fixedHeader().messageType() == MqttMessageType.PINGREQ){ System.out.println("===========服务端收到了ping请求=========="); this.handlePingReq(ctx.channel()); } else if(message.fixedHeader().messageType() == MqttMessageType.PINGRESP){ System.out.println("===========服务端收到了ping响应=========="); this.handlePingResp(); }else{ ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } }
Example 2
Source File: MqttPingHandler.java From smartacus-mqtt-broker with Apache License 2.0 | 5 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof MqttMessage)) { ctx.fireChannelRead(msg); return; } MqttMessage message = (MqttMessage) msg; if(message.fixedHeader().messageType() == MqttMessageType.PINGREQ){ this.handlePingReq(ctx.channel()); } else if(message.fixedHeader().messageType() == MqttMessageType.PINGRESP){ this.handlePingResp(); }else{ ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } }
Example 3
Source File: MqttPingHandler.java From smartacus-mqtt-broker with Apache License 2.0 | 5 votes |
private void sendPingReq(Channel channel){ MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0); channel.writeAndFlush(new MqttMessage(fixedHeader)); if(this.pingRespTimeout != null){ this.pingRespTimeout = channel.eventLoop().schedule(() -> { MqttFixedHeader fixedHeader2 = new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0); channel.writeAndFlush(new MqttMessage(fixedHeader2)).addListener(ChannelFutureListener.CLOSE); //TODO: what do when the connection is closed ? }, this.keepaliveSeconds, TimeUnit.SECONDS); } }
Example 4
Source File: MqttPingHandler.java From smartacus-mqtt-broker with Apache License 2.0 | 5 votes |
/** * 5秒钟收不到来自对方的ping,就关闭连接 * @param channel */ private void sendPingReq(Channel channel){ MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0); channel.writeAndFlush(new MqttMessage(fixedHeader)); /* if(this.pingRespTimeout == null){ this.pingRespTimeout = channel.eventLoop().schedule(() -> { MqttFixedHeader fixedHeader2 = new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0); channel.writeAndFlush(new MqttMessage(fixedHeader2)).addListener(ChannelFutureListener.CLOSE); //TODO: what do when the connection is closed ? }, this.keepaliveSeconds, TimeUnit.SECONDS); }*/ }
Example 5
Source File: PingReqHandler.java From joyqueue with Apache License 2.0 | 4 votes |
@Override public MqttMessageType type() { return MqttMessageType.PINGREQ; }
Example 6
Source File: MqttClientImpl.java From vertx-mqtt with Apache License 2.0 | 3 votes |
/** * See {@link MqttClient#ping()} for more details */ @Override public MqttClient ping() { MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0); io.netty.handler.codec.mqtt.MqttMessage pingreq = MqttMessageFactory.newMessage(fixedHeader, null, null); this.write(pingreq); return this; }