这是我所在组织的一位软件工程师提出的问题。我感兴趣的是最广义的定义。
当前回答
端口和插座可以比作银行分行。
“银行”的门牌号与IP地址类似。 银行有不同的部分,比如:
储蓄帐务部 个人贷款部 房屋贷款部 投诉部门
因此,1(储蓄账户部)、2(个人贷款部)、3(住房贷款部)和4(申诉部)是端口。
现在让我们假设你要开一个储蓄账户,你去了银行(IP地址),然后你去了“储蓄账户部门”(端口号1),然后你遇到了在“储蓄账户部门”工作的一名员工。让我们称他为SAVINGACCOUNT_EMPLOYEE1,用于开户。
SAVINGACCOUNT_EMPLOYEE1是套接字描述符,因此可能存在 SAVINGACCOUNT_EMPLOYEE1到SAVINGACCOUNT_EMPLOYEEN。这些都是套接字描述符。
同样地,其他部门将有员工在他们之下工作,他们类似于插座。
其他回答
I know that there are lot of explanations. But, there is one more easy way to understand with practical example. We all can connect to HTTP port 80, but does it mean only one user can connect to that port at a time?. The answer is obviously 'no'. Multiple users for multiple purposes can access HTTP port 80 but they still get proper response they are waiting for, from the server, can't they?. Now think about it for a minute, how?. Yes you are correct, its IP address that uniquely identifies different users who contacts for different purposes. If you would have read the previous answers before reaching here, you would know that IP address is a part of information that socket consists. Think about it, is it possible to have a communication without sockets?. The answer is 'Yes' but you cannot run more than one application in a port but we know that we are not a 'Dump' switch that runs on just hardware.
端口和插座可以比作银行分行。
“银行”的门牌号与IP地址类似。 银行有不同的部分,比如:
储蓄帐务部 个人贷款部 房屋贷款部 投诉部门
因此,1(储蓄账户部)、2(个人贷款部)、3(住房贷款部)和4(申诉部)是端口。
现在让我们假设你要开一个储蓄账户,你去了银行(IP地址),然后你去了“储蓄账户部门”(端口号1),然后你遇到了在“储蓄账户部门”工作的一名员工。让我们称他为SAVINGACCOUNT_EMPLOYEE1,用于开户。
SAVINGACCOUNT_EMPLOYEE1是套接字描述符,因此可能存在 SAVINGACCOUNT_EMPLOYEE1到SAVINGACCOUNT_EMPLOYEEN。这些都是套接字描述符。
同样地,其他部门将有员工在他们之下工作,他们类似于插座。
这些是基本的网络概念,所以我将以一种简单而全面的方式详细解释它们。
插座就像电话(即端到端通信设备) IP就像你的电话号码(即你的插座地址) 端口就像您想要与之交谈的人(即您想从该地址订购的服务) 插座可以是客户端也可以是服务器端(例如,在公司中,客户支持的电话是服务器,但你家里的电话主要是客户端)
因此,网络中的套接字是绑定到一对(ip,端口)=(地址,服务)的虚拟通信设备。
注意:
A machine, a computer, a host, a mobile, or a PC can have multiple addresses , multiple open ports, and thus multiple sockets. Like in an office you can have multiple telephones with multiple telephone numbers and multiple people to talk to. Existence of an open/active port necessitate that you must have a socket bound to it, because it is the socket that makes the port accessible. However, you may have unused ports for the time being. Also note, in a server socket you can bind it to (a port, a specific address of a machine) or to (a port, all addresses of a machine) as in the telephone you may connect many telephone lines (telephone numbers) to a telephone or one specific telephone line to a telephone and still you can reach a person through all these telephone lines or through a specific telephone line. You can not associate (bind) a socket with two ports as in the telephone usually you can not always have two people using the same telephone at the same time . Advanced: on the same machine you cannot have two sockets with same type (client, or server) and same port and ip. However, if you are a client you can open two connections, with two sockets, to a server because the local port in each of these client's sockets is different)
希望它能消除你的疑虑
端口:
端口可以指物理连接点 用于外部设备,如串行、并行和USB端口。 术语端口也指某些以太网连接点 如集线器、交换机或路由器上的那些。
套接字:
套接字表示两个网络应用程序之间的单个连接。 这两个应用程序名义上运行在不同的计算机上, 但是套接字也可以用于单台计算机上的进程间通信。 应用程序可以创建多个套接字用于相互通信。 套接字是双向的,这意味着连接的任何一方都能够发送和接收数据。
相对的TCP/IP术语,我认为这是隐含的问题。通俗地说:
PORT类似于特定邮政编码中特定房屋的电话号码。城镇的邮政编码可以被认为是城镇和城镇中所有房屋的IP地址。
另一方面,SOCKET更像是一对房屋之间的电话之间的通话。这些呼叫可以在同一城镇的房屋之间建立,也可以在不同城镇的两所房屋之间建立。这对手机之间建立的临时通道就是SOCKET。
推荐文章
- 模拟慢速互联网连接
- 127.0.0.1和localhost之间的区别是什么
- 为什么SCTP不常用/不为人所知
- 无法启动IIS Express Web服务器,注册URL失败,访问被拒绝
- 我可以在/etc/hosts中映射主机名*和端口*吗?
- 如何修改Play执行run命令时使用的默认端口(9000)?
- 连接网络共享时,如何提供用户名和密码
- 如何找到可用的端口?
- 如何通过windows命令行关闭TCP和UDP端口
- UDP和TCP比起来快多少?
- ssh -L转发多个端口
- 一个干净、轻量级的Python扭曲的替代品?
- 套接字的连接超时和读超时之间的区别是什么?
- 将主机端口转发到docker容器
- 远程主机强制关闭现有连接