当前位置: 首页>>代码示例>>Java>>正文


Java MqttConnectReturnCode.CONNECTION_ACCEPTED属性代码示例

本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_ACCEPTED属性的典型用法代码示例。如果您正苦于以下问题:Java MqttConnectReturnCode.CONNECTION_ACCEPTED属性的具体用法?Java MqttConnectReturnCode.CONNECTION_ACCEPTED怎么用?Java MqttConnectReturnCode.CONNECTION_ACCEPTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在io.netty.handler.codec.mqtt.MqttConnectReturnCode的用法示例。


在下文中一共展示了MqttConnectReturnCode.CONNECTION_ACCEPTED属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleConnack

/**
 * Used for calling the connect handler when the server replies to the request
 *
 * @param msg  connection response message
 */
void handleConnack(MqttConnAckMessage msg) {

  synchronized (this.connection) {

    this.isConnected = msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED;

    if (this.connectHandler != null) {

      if (msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
        this.connectHandler.handle(Future.succeededFuture(msg));
      } else {
        MqttConnectionException exception = new MqttConnectionException(msg.code());
        log.error(String.format("Connection refused by the server - code: %s", msg.code()));
        this.connectHandler.handle(Future.failedFuture(exception));
      }
    }
  }
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:23,代码来源:MqttClientImpl.java

示例2: connectionAlreadyAccepted

@Test
public void connectionAlreadyAccepted(TestContext context) throws Exception {

  this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED;

  MemoryPersistence persistence = new MemoryPersistence();
  MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence);
  client.connect();

  try {
    // try to accept a connection already accepted
    this.endpoint.accept(false);
    context.fail();
  } catch (IllegalStateException e) {
    // Ok
  }
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:17,代码来源:MqttServerConnectionTest.java

示例3: reject

public MqttEndpointImpl reject(MqttConnectReturnCode returnCode) {

    if (returnCode == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
      throw new IllegalArgumentException("Need to use the 'accept' method for accepting connection");
    }

    // sessionPresent flag has no meaning in this case, the network connection will be closed
    return this.connack(returnCode, false);
  }
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:9,代码来源:MqttEndpointImpl.java

示例4: accepted

@Test
public void accepted(TestContext context) {

  this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED;

  try {
    MemoryPersistence persistence = new MemoryPersistence();
    MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence);
    client.connect();
  } catch (MqttException e) {
    context.fail(e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:13,代码来源:MqttServerConnectionTest.java

示例5: acceptedClientIdAutoGenerated

@Test
public void acceptedClientIdAutoGenerated(TestContext context) {

  this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED;

  try {
    MemoryPersistence persistence = new MemoryPersistence();
    MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "", persistence);
    client.connect();
  } catch (MqttException e) {
    context.fail(e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:13,代码来源:MqttServerConnectionTest.java

示例6: endpointHandler

@Override
protected void endpointHandler(MqttEndpoint endpoint) {

  MqttConnectReturnCode returnCode = this.expectedReturnCode;

  switch (this.expectedReturnCode) {

    case CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD:

      returnCode =
        (endpoint.auth().userName().equals(MQTT_USERNAME) &&
          endpoint.auth().password().equals(MQTT_PASSWORD)) ?
          MqttConnectReturnCode.CONNECTION_ACCEPTED :
          MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD;
      break;

    case CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION:

      returnCode = endpoint.protocolVersion() == MqttConnectOptions.MQTT_VERSION_3_1_1 ?
        MqttConnectReturnCode.CONNECTION_ACCEPTED :
        MqttConnectReturnCode.CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION;
      break;
  }

  log.info("return code = " + returnCode);

  if (returnCode == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
    log.info("client id = " + endpoint.clientIdentifier());
    endpoint.accept(false);
  } else {
    endpoint.reject(returnCode);
  }

  this.endpoint = endpoint;
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:35,代码来源:MqttServerConnectionTest.java


注:本文中的io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_ACCEPTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。