.NET Framework - Open UDP port without specifying port number?
Is there a way to open an UDP port in .NET Framework without specifyi开发者_运维知识库ng port number, so the Framework finds a free port to you?
Just like Java when using:public ServerSocket(int port),
with port = 0.
Thanks!
It works very similar to your Java example:
var udpClient = new UdpClient(0);
IPEndPoint remoteEP = null;
byte[] data = udp.Receive( ref remoteEP );
Looking at netstat it appears that a different port is allocated each time.
精彩评论