简体   繁体   中英

tcp ip client read received data c#

TcpClient client = new(SERVER_IP, PORT_NO);
        NetworkStream stream = client.GetStream();
        stream.Write(WriteArry, 0, WriteArry.Length);
        
        byte[] data = new byte[10];
        
        int recivedbyte = stream.Read(data, 0, 10);

how can i check if Length of received data less than 10 wait more for Remaining data? or Data to received more than once? Thanks

byte[] data = new byte[10];

int read, remaining = data.Length;
while (remaining > 0 && (read =
    stream.Read(data, data.Length - remaining, remaining)) > 0)
{
    remaining -= read;
}
if (remaining != 0) throw new EndOfStreamException(); // EOF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM