@Override
  public CoapResponse createSeparateResponse(CoapRequest request, CoapResponseCode responseCode) {

    BasicCoapResponse response = null;
    if (request.getPacketType() == CoapPacketType.CON) {
      /* The separate Response is CON (normally a Response is ACK or NON) */
      response =
          new BasicCoapResponse(
              CoapPacketType.CON,
              responseCode,
              channelManager.getNewMessageID(),
              request.getToken());
      /*send ack immediately */
      sendMessage(new CoapEmptyMessage(CoapPacketType.ACK, request.getMessageID()));
    } else if (request.getPacketType() == CoapPacketType.NON) {
      /* Just a normal response*/
      response =
          new BasicCoapResponse(
              CoapPacketType.NON, responseCode, request.getMessageID(), request.getToken());
    } else {
      throw new IllegalStateException(
          "Create Response failed, Request is neither a CON nor a NON packet");
    }

    response.setChannel(this);
    return response;
  }
  @Override
  public CoapResponse createNotification(
      CoapRequest request, CoapResponseCode responseCode, int sequenceNumber, boolean reliable) {
    BasicCoapResponse response = null;
    CoapPacketType packetType;
    if (reliable) {
      packetType = CoapPacketType.CON;
    } else {
      packetType = CoapPacketType.NON;
    }

    response =
        new BasicCoapResponse(
            packetType, responseCode, channelManager.getNewMessageID(), request.getToken());
    response.setChannel(this);
    response.setObserveOption(sequenceNumber);
    return response;
  }
  @Override
  public BasicCoapResponse createResponse(
      CoapMessage request, CoapResponseCode responseCode, CoapMediaType contentType) {
    BasicCoapResponse response;
    if (request.getPacketType() == CoapPacketType.CON) {
      response =
          new BasicCoapResponse(
              CoapPacketType.ACK, responseCode, request.getMessageID(), request.getToken());
    } else if (request.getPacketType() == CoapPacketType.NON) {
      response =
          new BasicCoapResponse(
              CoapPacketType.NON, responseCode, request.getMessageID(), request.getToken());
    } else {
      throw new IllegalStateException(
          "Create Response failed, Request is neither a CON nor a NON packet");
    }
    if (contentType != null && contentType != CoapMediaType.UNKNOWN) {
      response.setContentType(contentType);
    }

    response.setChannel(this);
    return response;
  }