Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


Just I am writing a program which will establish a tcp client program.
After establishing the connection we are able to send and receive the messages from the both ends.
But when there is some network problem we are unable to get the response. At that time the hole application is going stop with any response. Can any one please suggestion how to set wait time or kill the thread in this situation.

this is following code.


Java
client = new Socket("serverAddress", portNumber);
OutputStream outToServer = client.getOutputStream();
DataOutputStream writeCommands =  new DataOutputStream(outToServer);
BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
String str2 = br.readLine();
Posted
Updated 25-Feb-14 0:57am
v3

1 solution

If you make sure you are handling any exceptions then you should be okay.
When the network "goes down" then the session should eventually die. There is a timeout after which a socket will close if it has not received a handshake. You can try this by having two machines for the client and server and then disconnect one from the network.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900