Search code examples
c#ibm-cloudwatson-iot

SocketException after publishCommand, ApplicationClient


I have created an application in the IBM Watson IoT Platform, and I used the code sample provided to connect an ApplicationClient object.

The connection is fine, but when the publish command is sent, after a second or two I got this in the output window of VS2017:

Exception levée : 'System.Net.Sockets.SocketException' dans System.dll
Exception levée : 'System.IO.IOException' dans System.dll
Exception levée : 'System.IO.IOException' dans System.dll
Le thread 0x4a4 s'est arrêté avec le code 0 (0x0).
Exception levée : 'System.Security.Cryptography.CryptographicException' 
dans mscorlib.dll

the thing is, I have used try/catch block everywhere, but they don't catch those exceptions.

I can guess it's about ports forwarding but even after opening the ports required by watson iot, I can't seem to have the command working

I can successfully publish events from device and reception those events on an ApplicationClient, I only have problems with Command.

EDIT: add clarification

  • I don't know which port exactly is used, its the IBMWIoTP who manage the connection, but the docs says to open 1883, 80, 8883 and 443. Which I did, both in the windows firewall and my router.

  • The publish method looks like this:

    appClient.publishCommand("Raspberry", "Pi2B", "pi", "txt", data, 0); where Raspberry is the device type; Pi2B the device id, pi the topic, txt the format, data is a string and 0 is the QoS.

  • I'm using the recommended Nuget library by IBM : IBMWIoTP

  • I tried to set TLS optional in security but this doesn't solve the issue

  • I found the exact moment I have the uncaught exception, in the IBMWIoTP library source code, on the connect method:

connevtionState = mqttClient.Connect(clientId, clientUsername, clientPassword,cleanSession,keepAlivePeriod);

Solution

  • Dropped connections can indicate you're trying to do something illegal, such as publishing to a topic you're not allowed to.