From reading a few questions and answers here, it seems that a telnet stream never really closes. Using DataAvailable() will not return.
I've inherited some code that took a very very long time to complete and we thought it was the telnet server that was the problem. However, there is a byte[32757] which the code tries to store the response of the telnet server in.
Something like the following:
Byte byteArray[] = new Byte[32757];
TcpClient sock = new TcpClient();
sock.GetStream().read(byteArray, 0 byteArray.length);
If there isn't 32757 bytes or more, I'm assuming this code waits until enough empty packets are sent to make up the size of the byte array. Is this correct?
Is there a way to check if the telnet server has finished sending everything it wants to? There is no visible terminating char or string in each 'page' of the telnet session.
I was thinking a way to correct this code is to read a few bytes at a time, add that to a string, check the string for a terminating character or set of chars and return if found. Otherwise, read more bytes, add that to the string, and check again.
Suggestions?