0
我使用下面的代码从服务器获取新闻组:没有收到所有数据与networkstream.read
sendBytes = Encoding.ASCII.GetBytes("LIST active microsoft.public*" & ControlChars.CrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Array.Clear(bytes, 0, bytes.Length)
If networkStream.CanRead Then
Do
numberOfBytesRead = networkStream.Read(myReadBuffer, 0, myReadBuffer.Length)
myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead))
intLenMyReadBuf = myReadBuffer.Length
intLenComplMsg = myCompleteMessage.Length
swWriter.WriteLine("buf len = " & intLenMyReadBuf & ", msg len = " & intLenComplMsg)
Loop While networkStream.DataAvailable
Else
Console.WriteLine("Sorry. You cannot read from this NetworkStream.")
End If
sendBytes = Encoding.ASCII.GetBytes("QUIT " & ControlChars.CrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
tcpClient.Close()
networkStream.Close()
当我执行的代码,程序只接收一个数据块。但是,如果我在循环指令中使用带有断点的 调试模式,则会收到所有数据块。
我是否在代码中遗漏了一些东西,比如等待什么东西,这会让程序
接收调试时发生的所有数据?
谢谢您的答复competent_tech。我从你的评论中学到了很多,现在我的程序运行得更好。 – Kool
@Kool:非常欢迎您,欢迎来到StackOverflow。请记住,如果您在本网站上回答您的问题可以帮助您解决问题,请点击问题旁边的复选标记和向上箭头,让未来的访问者知道该答案已解决或帮助您解决问题。 –