I have an application I wrote that has a telnet interface. Now, I am trying to automate some tasks by sending socket data through this interface to the program. My client can connect and send text, but for some reason does not read anything given to it from the server. The server is expecting the stream to be read and crashes when the connection closes and the stream hasn't been read. So, I need to implement some stream reading on the client..This is what I have so far.
I was wondering if there would be some way to loop after the text is sent to see if there is data in the stream and if there is, pluck it and clear the stream so the server doesn't choke and die...
I was wondering if there would be some way to loop after the text is sent to see if there is data in the stream and if there is, pluck it and clear the stream so the server doesn't choke and die...
VB.NET:
Dim Remote As String = Nothing
Remote = InputBox("Please insert the location of the remote host.", "Refresh")
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect(Remote, 5657)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("refresh" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Else
If Not networkStream.CanRead Then
MsgBox("cannot not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
MsgBox("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If