Hi, I'm currently using tcpclient command to establish tcpip communication with an external device (not tcpip() from instrument toolbox).
Sometimes, the connection is not stable and when I write data it returns error: 'An existing connection was forcibly closed by the remote host'.
Therefore, I want to implement a method to check the connection before I write / read from the connection. However, I just couldn't find much information regarding tcpclient.
I have attempted the following:
Here, before running the I deliberately disconnected Ethernet cable just want to test trigger the error:
For the first run 'An existing connection was forcibly closed by the remote host' still appears in the command window and the 'send successful' message is printed, catch statement is skipped. However, a second run will jump into catch statement though.
If I run the try-catch step by step, when it reaches 'write(t,0)' statement it returns the ''An existing ... remote host'', and continue to 'read(t)' statement, and jumps into catch statement.
I couldn't quite understand why this happened.
Thanks for your help very much!