How to specify source port of a UdpPacket?

后端 未结 1 869
野趣味
野趣味 2020-12-19 00:05

I wanted to send UdpPacket to a specific remote host (I already know the public IP and Port). I wanted to use C#\'s UdpClient class.

static int Main()
{
             


        
相关标签:
1条回答
  • 2020-12-19 00:36

    Try specifying the endpoint when you create the UdpClient:

    UdpClient client = new UdpClient(localEndpoint);
    

    EDIT: Note that you can also specify just the port number:

    UdpClient client = new UdpClient(localPort);
    

    That may be somewhat simpler :)

    0 讨论(0)
提交回复
热议问题