Is it necessary to attempt to connect to all addresses returned by getaddrinfo()?

后端 未结 5 2249
甜味超标
甜味超标 2021-02-14 16:33

Beej\'s Simple Client example code iterates over all IP addresses returned from getaddrinfo(), until it can connect to the first one. See the code below.

Is this always

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 17:01

    Let look at tit this way... The server host you want to connect to may have several addresses associated with it, but the actual server program only listens on one of those addresses. If your client doesn't know the exact address the server program is listening to, you have to try all the addresses the host has until you find the correct one and can connect.

提交回复
热议问题