E
Ed
Guys,
I have a piece of code that is reading from a socket until it receives
characters that indicate that it is end of the string. This is for a
telnet application and as people may know - a telnet response can come
back as one or many message.
Anyhow the problem is more generic than telnet so I don't want this to
confuse people.
The code block I have is as follows (message is a StringBuffer, reader
is a BufferedReader):
if (endOfResponseString != null)
{
//Read the response from the server
c = 0;
while((c = reader.read()) != -1)
{
message.append((char)c);
if (message.toString().endsWith(endOfResponseString))
{
break;
}
}
}
The problem is that when the server errors it never returns the
endOfResponseString I am looking for. The communication can take
seconds to finish but I would ideally like the reader.read or this
whole block to timeout after say 10 seconds.
Is there a simple way to do this? I do want the program to block for
the 10 seconds but after that time to break out.
Many thanks for any suggestions
Ed
I have a piece of code that is reading from a socket until it receives
characters that indicate that it is end of the string. This is for a
telnet application and as people may know - a telnet response can come
back as one or many message.
Anyhow the problem is more generic than telnet so I don't want this to
confuse people.
The code block I have is as follows (message is a StringBuffer, reader
is a BufferedReader):
if (endOfResponseString != null)
{
//Read the response from the server
c = 0;
while((c = reader.read()) != -1)
{
message.append((char)c);
if (message.toString().endsWith(endOfResponseString))
{
break;
}
}
}
The problem is that when the server errors it never returns the
endOfResponseString I am looking for. The communication can take
seconds to finish but I would ideally like the reader.read or this
whole block to timeout after say 10 seconds.
Is there a simple way to do this? I do want the program to block for
the 10 seconds but after that time to break out.
Many thanks for any suggestions
Ed