I am creating a UDP Server.I found following code reference from MSDN.Can any one please explain why they are using two IPEndPoint objects in the code sample.I assume second ipeEdpoint is the address of sender(Client). But how it is possible? Ip address of client can be extract from the Data gram packet, So what is the purpose for the second object here?This may be a simple and silly question but i am little confusing…:D
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
data = newsock.Receive(ref sender);
The call to the
UdpClientconstructor passes in the hosts end point. Receive starts the process of receiving data–which won’t do anything until another process makes a request to the end point you created in theUdpClientconstructor. When that connection does happen, the endpoint of the process sending data to yourUdpClientwill then be available. e.g. in thesendervariable.