Creating a reliable TCP Connection | Telit Cinterion IoT Developer Community
November 17, 2017 - 10:22am, 8540 views
I'm currently writing an application for the EHS6T board that is gathering data via a serial port and outputting over a TCP connection.
Currently I am using a SocketConnection and an OutputsSream as in the examples I have seen, however this doesn't seem to be the correct way of doing it as the OutputStream write function will block indefinately if I lose cell reception.
Am I missing something obvious or is this method not the best approach for my requirements? Obviously in case of losing the connection I want to buffer the data and then send it when I can re-establish the connection.
Thanks in advance.
Have you alreasy tested such scenario? You should finally get an exception in case of lost connection.
Thanks for the reply.
Yes I have, I never get an exception after leaving for several hours. What determines when this exception fires? Should I be setting a timeout somewhere?
Generally detecting a socket closure by the other party is problematic in Java especially when the connection is idle. At least it may take a long time to detect that thie other party is no longer reachable. I'd rather expect the exception in minutes rhather than hours in case of sending data to the host which is no longer connected. It should be sooner than in case of reading data from the remote host. But the fastest way of detecting a lost connection would be to implement a custom keep-alive messages - then you can decide after what timeout you treat the connection as lost. Or a reply from server after it receives data. Or just implementing some kind of timer and closing the connection that is assumed broken after the certain amount of time.
Thanks again for the reply, the socket closure isn't so much by the other party as by the module as it no longer has internet access. Would I be better sending data using the AT handler, would this and AT commands give me better visibility if the signal drops out?
Presumabily if I stuck with java i would have to do the timer and keep alive on a different thread as that thread is blocked by the write command?
Using IP connections over AT commands in the Java MIDlet is possible but generally the most recommended way is to use the Java classes only and especially not to use the two ways simultaneously. According to my expirience in case of AT commands detection of broken connection or network connection loss works faster.
Can you paste the ATI1 command output so I could verify what firmware version you have?
This is my ATI1:
If there's no network connection my module throws IOException: Profile could not be activated. As I remember this was always working like that. But maybe your scenario is a little different that you don't get it.
Your firmware is not the latest version. There is an update available: A-REVISION 00.000.51.
You can also try it.
Ok I will make a simplied test and see if I can get it to throw the exception, I will also update the firmware.
Roughly how long before the exception was thrown?
In my case it was around one minute in case of no network.
Where can I find this new firmware to try please?