Receiving a response through UDP

后端 未结 3 2076
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 18:52

I have seen applications send a packet through UDP to an IP on some port and receiving a response. Which port does the response go to? (Btw, how can the router know that the

3条回答
  •  忘掉有多难
    2021-01-04 19:37

    When you create the UDP socket, you must bind it to a port number. If you dont, the operating system will assign an ephemeral port.

    The application on the other side must know of this port. When replies are sent back, your router might not know how to route. There are 2 ways to resolve this problem

    1. You can explicitly configure a route to your computer on a particular port.
    2. You can configure your router to track the UDP connection by automatically opening a route to your computer when a particular packet is sent. UPNP protocol is based on this concept.

提交回复
热议问题