Sending and receiving UDP packets between two programs on the same computer

后端 未结 8 1821
慢半拍i
慢半拍i 2020-12-02 12:37

Is it possible to get two separate programs to communicate on the same computer (one-way only) over UDP through localhost/127... by sharing the same port #?

We\'re

8条回答
  •  没有蜡笔的小新
    2020-12-02 13:15

    You can bind to a port multiple times using the ReuseAddress socket option.

    UdpClient udpClient = new UdpClient();
    udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
    

    You'll need to set the same option on the UDP server socket as well.

提交回复
热议问题