I establish a standard TCP connection between two stations (A, B) A sends a message, B receives and sends a response back, and then I close the connections.
- Station B is a black box, I cannot change access or do anything there.
Sometimes a situation arises when B does not send a response back, and then I need to try the whole process again.
I want to set a timeout for the recovery time of station A (who are waiting for B to respond). So basically, when the timeout expired, I will send a retry.
I did not find a way to set a timeout for a DataInputStream. (only for the entire socket connection - which I don't want)
some code:
public byte[] receive(DataInputStream is) throws Exception
{
logger.debug(TAG + " Client Recieving...");
try
{
byte[] inputData = new byte[1024];
is.read(inputData);
return inputData;
} catch (Exception e)
{
throw new Exception(TAG + " Couldnt receive data from modem: " + e.getMessage());
}
}
Thanks ray.
source
share