I am establishing standart TCP connection between two stations(A,B) A is sending message, B recieving and sending response back, and then I close the connections.
- Stations B is "blackbox", I cant access change or do anything there.
Sometimes there is situation when B didnt send response back, and then I need to re-try the whole process again.
I want to set timeout on the reciveing time of Station A (which wait for B for an answer). So basically when the waiting time is expired, i will dispatch a retry.
I didnt find a way how to set a timeout for DataInputStream. (only for the whole socket connection - which I dont want)
some code:
/**
* Method receives the Server Response
*/
public byte[] receive(DataInputStream is) throws Exception
{
logger.debug(TAG + " Client Recieving...");
try
{
byte[] inputData = new byte[1024];
// here I want to set timeout for the "receiving mode"
is.read(inputData);
return inputData;
} catch (Exception e)
{
throw new Exception(TAG + " Couldnt receive data from modem: " + e.getMessage());
}
}
Thanks, ray.