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

后端 未结 8 1759
慢半拍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.

    0 讨论(0)
  • 2020-12-02 13:15

    Only one program can bind to a port at a time. Multiple programs can connect to one port on another system's, but the local port your different web browsers have bound themselves to is randomly assigned.

    Unless you want to do some ugly inter-process communication or packet sniffing, there's no way to have multiple programs bound to one port.

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