What client-side situations need bind()?

后端 未结 7 1732
长情又很酷
长情又很酷 2021-01-01 16:21

I\'m learning C socket programming. When would you use bind() on the client-side? What types of program will need it and why? Where can I find an example?

7条回答
  •  长情又很酷
    2021-01-01 16:32

    On the client side, you would only use bind if you want to use a specific client-side port, which is rare. Usually on the client, you specify the IP address and port of the server machine, and the OS will pick which port you will use. Generally you don't care, but in some cases, there may be a firewall on the client that only allows outgoing connections on certain port. In that case, you will need to bind to a specific port before the connection attempt will work.

提交回复
热议问题