I’m trying to make my server more stable. It uses the server socket and socket classes. The transferring of information is done using the stream class.
I notice that sometimes when debugging is would frees every ounce in a while.
I found out that id my client just did a socket connection and did not send over and data, or less then the server was expecting the server would freeze on the read method for class InputStream.
Is there a way to get the read method to time out? The document ion does not talk about time pouts, but does say it will block info data is amiable.
If the read cannot do a time out, is there another way to read the data over the socket connection and not freeze if the client is no longer sending data????
code snippet of reading in data and where it freezes
public String ReadLine(){
String out="";
// read in one line
try{
request = new StringBuffer(1000);
boolean f=true;
while(true){
int c=in.read(); // WILL FREEZ HEAR IF CLIENT NO LONGER CONNECTED OR SENDING DATA
if (c=='\r'){
// next should be a \n
c=in.read();
//.....
If you are using sockets then you need to set the SO_TIMEOUT value on the socket. This will allow reads to time out and throw an
InterruptedIOException.Socket.setSoTimeoutis the method to look at. Note that the timeout is set on the socket itself, not on the input stream obtained from the socket.