Gemalto is now part of the Thales Group, find out more.

You are here

[EHS6] Timeouts and blocking IO | Thales IoT Developer Community

October 31, 2014 - 11:55am, 3259 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)