我有以下代码,它将未知大小的数据读入内存流。
Dim cl As New Net.Sockets.TcpClient()
cl.Connect(host, port)
Dim st As IO.Stream = cl.GetStream()
Dim bytes(50000) As Byte
Dim mem As New IO.MemoryStream()
Dim len As Integer = 0
Do
len = st.Read(bytes, 0, 50000)
mem.Write(bytes, 0, len)
Loop While len > 0
mem.Close()
它工作正常,但唯一的问题是最后一次读取总是在返回 0 之前阻塞 20 秒。我假设这是某种超时。有没有办法缩短或消除它?