[EHS6] Timeouts and blocking IO | Telit Cinterion IoT Developer Community
October 31, 2014 - 11:55am, 4593 views
I have some problems with the EHS6 regarding timeouts and interrupting blocking IO.
First timeouts. The Connector.open method can accept a parameter 'timeout' and if the underlaying protocolimplementation implemented a timeout a exception will be thrown when a timeout occurs.
I expect an timeout after 5 seconds no data on the inputstream with the following code. But it does nog happen?
client = (SocketConnection) Connector.open("socket://192.168.34.250:4444;bearer_type=gprs;access_point=apn.maingate;username=;password=;timeout=5;reverse_dns_lookup=no", Connector.READ_WRITE, true); input = client.openInputStream(); int red; byte[] buff = new byte[512]; Debug.getInstance().info("READING"); while ((red = input.read(buff)) > 0) { Debug.getInstance().info("ch: " + (int) red); }
Second, what is the best way to interrupt blocking IO? I already implemented and inputstream using nonblocking streams i.c.m. the availeble() method to wait for data and throw an timeout exception. But without a call to any read method you cannot know if the socket is closed.
So please some examples / explaination how to solve the two problems. (Also regarding the serialport streams)
Hi,
The "timeout" parameter that you use in the connection string is defined as the number of seconds to wait before the network connection is terminated automatically after having closed the last socket on this connection. You can find more about this parameter in the AT Commands specification document (AT^SJNET command). Additionally according to Java API the "timeouts" parameter does not guarantee that such exceptions will actually be thrown.
The socket problem is connected with TCP protocol and it may take a really long time to get notified that the other party has closed the socket. There's probably no one and simple solution for that. If you are using your own protocol on top of the socket connection maybe implementing your custom keepalive notification is worth consideration then.
Best regards,
Bartłomiej
Hi Eppie,
I am trying to open a tcp socket in a public ip (my server) using gprs but I having no success. The socket seems to be connected but it is not able to receive data when it should be. Also, the method read() blocks for a while but it gets only -1 after around 30 seconds. My code looks pretty much like your code.
Is it necessary to setup the modem using AT commands before starting my Java application for connecting on internet?
If some Gemalto engineer can help me, please, I would appreciate that.
Thank you!
Hello,
To use internet connection in Java you only need to provide access point data. You can do it like above in the Connector.open() method or you can use AT^SJNET command.
Of course first thing you need to do is entering PIN (if the SIM card requires) and check if the module has registered to the network. You need AT commands for that but you can do it from the Java application.
The read() method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
You open the connection and read - does your server write anything then? Have you tried to trace on the server side?
Maybe the signal quality is low. Does your subscription include data transfer? Are there any exceptions thrown? It's hard to predict now what can be wrong.
Please also try to install and run the NetDemo application - you can find it under this or similar path: C:\Users\Public\Cinterion\EHS5 WTK Examples\EclipseSamples\NetDemo
If the module is registered to the network and you update the APN registration data this should be working.
Best regards,
Bartłomiej
Hi Bertolomiej,
Thank you for your quick reply.
I had a problem with my simcard. I have exchange the simcard and now it is working.
Thanks!!