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

后端 未结 8 1798
慢半拍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:03

    My advice: don't pass the port number into the UdpClient constructor. From the documentation, (somewhat sparse, I know...) it looks like if you do, the UdpClient will try to bind to that port (which, as sysrqb mentioned, is not allowed). (If you don't, I believe the UdpClient will listen on a random port for any replies. You could also pick a port you know to be unused.)

    When you call Connect() you need to pass in the port number the server is listening on.

提交回复
热议问题