这是我所在组织的一位软件工程师提出的问题。我感兴趣的是最广义的定义。


当前回答

端口和插座可以比作银行分行。

“银行”的门牌号与IP地址类似。 银行有不同的部分,比如:

储蓄帐务部 个人贷款部 房屋贷款部 投诉部门

因此,1(储蓄账户部)、2(个人贷款部)、3(住房贷款部)和4(申诉部)是端口。

现在让我们假设你要开一个储蓄账户,你去了银行(IP地址),然后你去了“储蓄账户部门”(端口号1),然后你遇到了在“储蓄账户部门”工作的一名员工。让我们称他为SAVINGACCOUNT_EMPLOYEE1,用于开户。

SAVINGACCOUNT_EMPLOYEE1是套接字描述符,因此可能存在 SAVINGACCOUNT_EMPLOYEE1到SAVINGACCOUNT_EMPLOYEEN。这些都是套接字描述符。

同样地,其他部门将有员工在他们之下工作,他们类似于插座。

其他回答

A socket represents a single connection between two network applications. These two applications nominally run on different computers, but sockets can also be used for interprocess communication on a single computer. Applications can create multiple sockets for communicating with each other. Sockets are bidirectional, meaning that either side of the connection is capable of both sending and receiving data. Therefore a socket can be created theoretically at any level of the OSI model from 2 upwards. Programmers often use sockets in network programming, albeit indirectly. Programming libraries like Winsock hide many of the low-level details of socket programming. Sockets have been in widespread use since the early 1980s.

端口表示网络通信的端点或“通道”。端口号允许同一计算机上的不同应用程序在不相互干扰的情况下利用网络资源。端口号最常出现在网络编程中,尤其是套接字编程中。但是,有时端口号对普通用户是可见的。例如,一个人在因特网上访问的一些网站使用如下URL:

http://www.mairie-metz.fr:8080/在本例中,数字8080指Web浏览器连接到Web服务器所使用的端口号。通常,Web站点使用端口号80,该端口号不需要包含在URL中(尽管可以包含)。

在IP组网中,端口号理论上可以在0到65535之间。但是,大多数流行的网络应用程序使用范围较低的端口号(例如HTTP的80)。

注意:术语端口还指网络技术的其他几个方面。端口可以指外部设备的物理连接点,如串口、并口和USB端口。术语端口也指某些以太网连接点,例如集线器、交换机或路由器上的连接点。

ref http://compnetworking.about.com/od/basicnetworkingconcepts/l/bldef_port.htm

ref http://compnetworking.about.com/od/itinformationtechnology/l/bldef_socket.htm

相对的TCP/IP术语,我认为这是隐含的问题。通俗地说:

PORT类似于特定邮政编码中特定房屋的电话号码。城镇的邮政编码可以被认为是城镇和城镇中所有房屋的IP地址。

另一方面,SOCKET更像是一对房屋之间的电话之间的通话。这些呼叫可以在同一城镇的房屋之间建立,也可以在不同城镇的两所房屋之间建立。这对手机之间建立的临时通道就是SOCKET。

它们是来自两个不同领域的术语:“端口”是TCP/IP网络的概念,“套接字”是API(编程)的东西。“套接字”是通过将端口和主机名或网络适配器组合成一个数据结构(可以用来发送或接收数据)而形成的(在代码中)。

套接字= IP地址+端口(数字地址) 它们一起标识机器上网络连接的端点。(我刚刚是不是网络基础课不及格?)

这个问题已经有了理论上的答案。我想举一个实际的例子来解释这个问题,让大家对Socket和Port有一个更清晰的理解。

我在这里找到的

This example will walk you thru the process of connecting to a website, such as Wiley. You would open your web browser (like Mozilla Firefox) and type www.wiley.com into the address bar. Your web browser uses a Domain Name System (DNS) server to look up the name www.wiley.com to identify its IP address is. For this example, the address is 192.0.2.100. Firefox makes a connection to the 192.0.2.100 address and to the port where the application layer web server is operating. Firefox knows what port to expect because it is a well-known port . The well-known port for a web server is TCP port 80. The destination socket that Firefox attempts to connect is written as socket:port, or in this example, 192.0.2.100:80. This is the server side of the connect, but the server needs to know where to send the web page you want to view in Mozilla Firefox, so you have a socket for the client side of the connection also. The client side connection is made up of your IP address, such as 192.168.1.25, and a randomly chosen dynamic port number. The socket associated with Firefox looks like 192.168.1.25:49175. Because web servers operate on TCP port 80, both of these sockets are TCP sockets, whereas if you were connecting to a server operating on a UDP port, both the server and client sockets would be UDP sockets.