Thanks for your reply @Sander van de Velde | MVP ,
Whenever I run Python code to send a Device-to-cloud message from my PC (following this tutorial: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-python-python-c2d), and run the Message Handler python code on the same PC, both programs run fine. One python file sends telemetry data to Azure IoT Hub, and the Message Handler python code receives the message without issue.
However the problem is, whenever I start running the device-to-cloud messaging Python file on my RaspberryPi 4 device, the message handler python file on my PC AND the python file sending device-to-cloud messages from my RaspberryPI starts getting the error:
Exception caught in background thread. Unable to handle.
["azure.iot.device.common.transport_exceptions.ConnectionDroppedError: ConnectionDroppedError('Unexpected disconnection') caused by ConnectionDroppedError('The connection was lost.')\n"]
I seen this reply on a githhub forum and it resonated with me as a possible explanation for why the device-to-cloud python file being hosted on my RaspberryPI 4 device and my PC message receiver python file are constantly trying to connect as the same device and it is causing them to ping-pong back and forth and that's why I'm getting spammed the ConnectionDroppedError on both Python Consoles:
(https://github.com/Azure/azure-iot-sdk-python/issues/399)
The other thing, which comes up more often than you might think, is when 2 different clients are connecting using the same device credentials. If there's 2 processes both trying to connect as the same device, they can ping-pong back and forth. One process would connect, which causes the second process to disconnect, then when the second process reconnects, it causes the first process to disconnect, and so on.
Whenever I run this https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-live-data-visualization-in-web-apps Javascript message receiver application, and sends telemetry data from my RaspberryPi 4 to Azure IoT Hub, the Javascript receives the messages without any connection dropped error.