Java Code Examples for io.netty.handler.codec.mqtt.MqttMessageType#PINGRESP

The following examples show how to use io.netty.handler.codec.mqtt.MqttMessageType#PINGRESP . 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 vote down vote up
@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 vote down vote up
@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: PingReqHandler.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(Channel client, MqttMessage message) throws Exception {
    String clientId = NettyAttrManager.getAttrClientId(client);
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("PingRequest clientId:%s", clientId));
    }
    MqttFixedHeader pingHeader = new MqttFixedHeader(
            MqttMessageType.PINGRESP,
            false,
            AT_MOST_ONCE,
            false,
            0);
    MqttMessage pingResp = new MqttMessage(pingHeader);
    client.writeAndFlush(pingResp);
}
 
Example 4
Source File: MqttPingHandler.java    From smartacus-mqtt-broker with Apache License 2.0 4 votes vote down vote up
private void handlePingReq(Channel channel){
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
    channel.writeAndFlush(new MqttMessage(fixedHeader));
}
 
Example 5
Source File: MqttPingHandler.java    From smartacus-mqtt-broker with Apache License 2.0 4 votes vote down vote up
private void handlePingReq(Channel channel){
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
    channel.writeAndFlush(new MqttMessage(fixedHeader));
    System.out.println("================服务端发送ping给客户端============");
    System.out.println(fixedHeader.toString());
}
 
Example 6
Source File: MessageUtil.java    From iot-mqtt with Apache License 2.0 4 votes vote down vote up
public static MqttMessage getPingRespMessage(){
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP,false,MqttQoS.AT_MOST_ONCE,false,0);
    MqttMessage mqttMessage = new MqttMessage(fixedHeader);
    return mqttMessage;
}
 
Example 7
Source File: PingRespHandler.java    From joyqueue with Apache License 2.0 4 votes vote down vote up
@Override
public MqttMessageType type() {
    return MqttMessageType.PINGRESP;
}
 
Example 8
Source File: MqttMessageFactory.java    From lannister with Apache License 2.0 4 votes vote down vote up
public static MqttMessage pingresp() {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false,
			0);

	return new MqttMessage(fixedHeader);
}
 
Example 9
Source File: MQTTProtocolHandler.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
void handlePingreq() {
   MqttMessage pingResp = new MqttMessage(new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0));
   sendToClient(pingResp);
}
 
Example 10
Source File: MqttEndpointImpl.java    From vertx-mqtt with Apache License 2.0 3 votes vote down vote up
public MqttEndpointImpl pong() {

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);

    io.netty.handler.codec.mqtt.MqttMessage pingresp = MqttMessageFactory.newMessage(fixedHeader, null, null);

    this.write(pingresp);

    return this;
  }