PDA

View Full Version : دسترسی به محتویات بسته UDP



yasamin64
شنبه 03 مهر 1395, 15:50 عصر
با سلام خدمت تمامی دوستان

چطور می توانم در یک بسته UDP در بحث سوکت پروگرامینگ به تمام محتویات بسته از جمله آدس پورت و ip مبدا و مقصد دسترسی پیدا کنم؟
با تشکر

ali_md110
شنبه 03 مهر 1395, 17:12 عصر
یک مثال از سایت msdn


UdpClient receivingUdpClient = new UdpClient(11000);


IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
try
{

// Blocks until a message returns on this socket from a remote host.
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);

string returnData = Encoding.ASCII.GetString(receiveBytes);

Console.WriteLine("This is the message you received " +
returnData.ToString());
Console.WriteLine("This message was sent from " +
RemoteIpEndPoint.Address.ToString() +
" on their port number " +
RemoteIpEndPoint.Port.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}