开发者

.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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜