How to receive multiple packets using UdpClient class?

44 views Asked by At

First of all, sorry for my bad English. I made a simple client/server program using UdpClient in C#. I have a problem. In order to send a big file (like a pdf for example), I use this code on client-side:

    private void WorkOnBuffer(byte[] buffer)
    {
        int cnt = buffer.Length/buffMax; //buffMax = 64000
        byte[] subBuffer = new byte[buffMax];
        int min = 0;

        for (int i = 0; i < cnt; i++)
        {
            Array.Copy(buffer, min, subBuffer, 0, buffMax);
            client.Send(subBuffer, subBuffer.Length);
            min += buffMax;
        }
    }

There is a loop which send bytes sub-array, made from main bytes array (for example, from pdf or txt). On server-side, how I can read all these packets? With method:

client.Receive(ref endPoint)  // endpoint instance of IPEndPoint

I read only one array byte. What's my mistake?

0

There are 0 answers