Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i create a program that receive UDP packet from multiple host ...

my question :

if all remote host send UDP packet at same time to my program , do my program can get all udp packet and handle all packets ?

do any packet lost if all upd receive at same time to my program ?

this is my code :
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;
using System.Net.Sockets;


namespace ler_Manager
{
    class Program
    {
        static UdpClient udp;
        static void UDPReciver(IAsyncResult res)
        {
            IPEndPoint remote = new IPEndPoint(IPAddress.Any, 8050);
            byte[] buffer = udp.EndReceive(res, ref remote);
            string encryptedString = Encoding.Default.GetString(buffer);
            Decrypt dec = new Decrypt(@"C:\privatekey.txt");
            //Console.WriteLine("Write New Value");
            Console.WriteLine(dec.DecryptStringToString(encryptedString));
            udp.BeginReceive(new AsyncCallback(UDPReciver), null);
 
        }

        static void Main(string[] args)
        {
            
            udp = new UdpClient(8050);

            udp.BeginReceive(new AsyncCallback(UDPReciver), null);
            Console.ReadLine();
            
        }
    }
}
Posted
Comments
Rob Philpott 13-Feb-15 11:17am    
There are no guarantees on packet delivery. Some do just go missing (usually ditched by a router along the way). TCP builds over the top of UDP to detect this and resend when required.

If you want to use UDP, you need to manage lost packets and stuff arriving out of order yourself.
Subhash Saini 11-Jan-17 7:15am    
Its great.. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900