Restrictions on deviceClient

Slava A 106 Reputation points
2020-11-02T21:41:48.793+00:00

opening two device clients: DeviceClient client = new DeviceClient(connString, protocol); client.open()
with the same connection string from two different processes is causing both processes to fail: com.microsoft.azure.sdk.iot.device.exceptions.TransportException: An unknown transport exception occurred
Is there a restriction to a single connection to a device for Iot Hub?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,143 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
211 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sander van de Velde | MVP 30,396 Reputation points MVP
    2020-11-03T17:19:10.887+00:00

    Before the IoT Hub was made available, the EventHub was the way to send telemetry to the cloud.

    The drawback was the shared key. all devices used the same key. If one device was compromised, all devices were compromised.

    The only way to protect your key was to switch between primary and secondary keys.

    If you still want to share the same credentials to a single cloud connection, consider an EventHub. This will ignore everything in an IoT Hub, it's just using another resource.

    WARNING: Keep in mind, IoT Hub is superior to the Event Hub both in features and security!

    2 people found this answer helpful.
    0 comments No comments

  2. QuantumCache 20,106 Reputation points
    2020-11-03T03:20:34.7+00:00

    Hello @Slava A , Thanks for posting this question!

    We can have multiple connections, but we need to create a separate device connection string for each process that runs an instance of a DeviceClient.

    Please refer to the below response provided by @António Sérgio Azevedo on MSDN.

    Using the same connection string is not supported and you will see unexpected errors. Only one device can use the same connection string at a time. Eg: if you have 2 devices connecting with the same ID, where would IoTHub send the C2D message or the Direct Method?

    I advise you to use Modules Instead (see here)

    "On the device side, the IoT Hub device SDKs enable you to create modules where each one opens an independent connection to IoT Hub. This functionality enables you to use separate namespaces for different components on your device."

    Please let me know if you need further help in this matter.

    1 person found this answer helpful.