How to UDP send and receive on same port?

前端 未结 2 722
故里飘歌
故里飘歌 2021-02-14 02:21

I need to be able to send and receive UDP packets on the same port. I am able to listen, on say port 5000, but my send uses a random high port. The system I am working written i

2条回答
  •  情话喂你
    2021-02-14 02:44

    A bidirectional communication link always involves two participants: a server-side and a client-side.

    The client expects to communicate to a server on a defined port: that's why on the server-side one must bind() to a socket.

    On the client-side, one must open a socket to the server: it doesn't really matter which socket is chosen (except for the need for it to be free).

    In other words, don't try to specify a socket on the client-side: the network protocol stack will assign it to your client.

提交回复
热议问题