在vb.net TCP客户端没有收到来自服务器的整个数据响应数据数据、客户端、服务器、vb

2023-09-06 22:17:32 作者:小地球很安全,不需要超人

我有一个小程序,它是一个TCP客户端。余发送的字符串从该客户机到一个设备上的以太网(它充当TCP服务器)。只要设备临危输入字符串它将响应回响应数据。我的问题是我没有得到整个响应数据从服务器返回。 (设备)。

I have a small program which is a tcp client. I send a string from this client to a device over ethernet (it acts as the tcp server). As soon as the device recieves the input string it will respond back with response data. My problem is i am not getting the entire response data back from the server. (device).

   Dim serverStream As NetworkStream = clientSocket2.GetStream()
   Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("my-cmd")
   serverStream.Write(outStream, 0, outStream.Length)

   'serverStream.Flush()
   Dim inStream(clientSocket2.ReceiveBufferSize) As Byte
   serverStream.Read(inStream, 0, CInt(clientSocket2.ReceiveBufferSize))        
   returndata = System.Text.Encoding.ASCII.GetString(instream)

Returndata没有充分响应从服务器返回(设备)

Returndata does not have the full response back from the server(device)

推荐答案

其实这是很简单的。我只是给了一些延迟读取流之前。问题是,整个流可以被读取之前的程序的执行来执行下一行。有一点延迟确信,整个数据流被检索。不管怎样,谢谢

Actually it was very simple. I just gave some delay before reading the stream. The problem was that before the entire stream could be read the program execution came to the next line. A little delay made sure that the entire stream of data is retrieved. Thanks anyway