开发者

.NET Framework - Open UDP port without specifying port number?

开发者 https://www.devze.com 2023-02-03 17:17 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消