Connection resets after a minute,.

K

Kalpesh Modha

Hello All.

What I am doing is after my class below connects to the server. I
disconnect the network cable from the computer. If I reconnect the network
cable after about a minute or so all is well and the client works correctly.

However if I remove the network cable but this time send some data like a OK
message using the writeMessage method all works, but after a minute the
replyRead = dataReader.readLine(); fails with a null, with results in a
connection reset message. The network cable is still disconnected at this
time.

I think that the print writer has sent the information to the TCP buffer, as
the system can not do anything and is waiting.
Is there a timer I can increase ?

What I am trying to achieve is that the client should should work over a
VPN, I get this connection reset after a while periodically. I guess the
VPN is very hostile.

The TIMEOUT value is set to 2 minutes.

many thianks for your help.
Kalpesh Modha

class dataWorker extends Thread
{
// server connection stuff
private Socket dataConnection = null;
private BufferedReader dataReader = null;
private PrintWriter dataWriter = null;

private String lastMessageSent = ""; // last message sent

// thread bit
public void run()
{
String replyRead = "";
try {

// make a connection to the master server.
dataConnection = new
Socket(setting.getDataServerAddress(),setting.getDataServerPort());
dataReader = new BufferedReader(new
InputStreamReader(dataConnection.getInputStream()));
dataWriter = new PrintWriter(dataConnection.getOutputStream(),true);

//dataConnection.setSoLinger(true,LINGER);
dataConnection.setSoTimeout(TIMEOUT);
System.out.println("Data TImeout: " + dataConnection.getSoTimeout());
System.out.println("Data linger value: " + dataConnection.getSoLinger());

} catch(UnknownHostException e)
{
writeLogEntry(ERROR_MESSAGE + "Unknown Host Data Worker: " +
e.getMessage());
errorOccured(ERROR_MESSAGE + "Unknown Host Data Worker: " +
e.getMessage());
} catch(IOException e)
{
writeLogEntry(ERROR_MESSAGE + "Error Data Worker: " + e.getMessage());
errorOccured(ERROR_MESSAGE + "Error Data Worker: " + e.getMessage());
}


try {
// greeting
dataReader.readLine();
} catch(IOException e)
{
writeLogEntry("Failed to get greeting data:" + e.getMessage());
writeLogEntry("DATA Cause SOURCE: " + e.getCause());
e.printStackTrace();
}

// this will set our name
writeDataMessage(COMMAND_SETNAME + " " + setting.getLogin());

// write entry we have logged in correctly
writeReason("Log Successful","");

// send the command to get the dialling codes.
writeDataMessage(COMMAND_PREFIX);

try {
while (true)
{
/*** this breaks with a null. ***/
replyRead = dataReader.readLine();

/*** other code removed ***/

}
}
catch(IOException ioe)
{
writeLogEntry("IOException in Data:" + ioe.getMessage());
writeLogEntry("DATA Cause SOURCE: " + ioe.getCause());
ioe.printStackTrace();
}
catch(Exception e)
{
writeLogEntry("Exception in Data:" + e.getMessage());
writeLogEntry("DATA Cause SOURCE: " + e.getCause());
e.printStackTrace();
} finally {
try {
dataReader.close();
} catch(IOException I ){}
finally{
dataReader = null;
}

try {
dataWriter.close();
} catch(Exception i) {}
finally {
dataWriter = null;
}

try {
dataConnection.close();
} catch(IOException i) {}
finally{
dataConnection = null;
}
}

}

public void writeMessage(String temp)
{
lastMessageSent = temp;//save the last message
dataWriter.println(temp);
}
// end of dataWorker class
}
 
S

Steve Horsley

Kalpesh said:
Hello All.

What I am doing is after my class below connects to the server. I
disconnect the network cable from the computer. If I reconnect the network
cable after about a minute or so all is well and the client works correctly.

However if I remove the network cable but this time send some data like a OK
message using the writeMessage method all works, but after a minute the
replyRead = dataReader.readLine(); fails with a null, with results in a
connection reset message. The network cable is still disconnected at this
time.

I think that the print writer has sent the information to the TCP buffer, as
the system can not do anything and is waiting.
Is there a timer I can increase ?

What I am trying to achieve is that the client should should work over a
VPN, I get this connection reset after a while periodically. I guess the
VPN is very hostile.

<code snipped>

I don't think there is anything you can do in java to change the underlying
TCP retransmission timers and counters. I would suggest that you change your
appllication to accept the possibility of such disconnections and to then
attempt to open a new connection in its place. Once you get this working,
your application will be extremely robust.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top