Topic
No replies
SystemAdmin
SystemAdmin
757 Posts
ACCEPTED ANSWER

Pinned topic Socket Timeout Exception

‏2013-03-20T10:11:58Z |
Hi I have developed a code to communicate to server using TCP/IP. I am getting the data too from the server, but after reading all the data every time the TimeoutException is raised and going to catch block.

The following is the code, can any one identify the wrong i did.
try {
if(echoSocket == null)
echoSocket = new Socket(hostAddress, serverPort);

if(echoSocket.getInetAddress() != null)
{
out = new PrintWriter(echoSocket.getOutputStream(), true);
String userInput=command.concat(" \r") ;
out.println(userInput);
out.flush();
echoSocket.setSoTimeout(timeout);
br = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
responseLine = "";

while((value = br.read()) != -1)
{
char c = (char)value;
responseLine = responseLine + c;
}

}
} catch (java.net.SocketTimeoutException e) {
e.printStackTrace();
}