哪些客户端情况需要bind()? [英] What client-side situations need bind()?

查看:15
本文介绍了哪些客户端情况需要bind()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 C 套接字编程.什么时候在客户端使用 bind()?什么类型的程序需要它,为什么?在哪里可以找到示例?

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?

推荐答案

在客户端,如果你想使用特定的客户端端口,你只会使用绑定,这很少见.通常在客户端上,您指定服务器机器的 IP 地址和端口,操作系统将选择您将使用的端口.通常你不关心,但在某些情况下,客户端上可能有防火墙,只允许在特定端口上的传出连接.在这种情况下,您需要先绑定到特定端口,然后连接尝试才会起作用.

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.

这篇关于哪些客户端情况需要bind()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆