这是我所在组织的一位软件工程师提出的问题。我感兴趣的是最广义的定义。
当前回答
似乎有很多答案将socket等同于2台PC之间的连接。我认为这是完全错误的。套接字一直是一台PC上的端点,可能连接也可能不连接-当然我们都在某些时候使用侦听器或UDP套接字*。重要的部分是它是可寻址的和活跃的。向1.1.1.1:1234发送消息不太可能起作用,因为没有为该端点定义套接字。
套接字是特定于协议的-因此,TCP/IP和UDP/IP都使用* (ipaddress:port)的唯一性实现与eg不同。, IPX (Network, Node, and…嗯哼,套接字——但是一个不同的套接字是指一般的“套接字”术语。IPX套接字号相当于IP端口)。但是,它们都提供了唯一的可寻址端点。
由于IP已成为主导协议,端口(在网络术语中)已成为UDP或TCP端口号的同义词——后者是套接字地址的一部分。
UDP is connection-less - meaning no virtual circuit between the 2 endpoints is ever created. However, we still refer to UDP sockets as the endpoint. The API functions make it clear that both are just different type of sockets - SOCK_DGRAM is UDP (just sending a message) and SOCK_STREAM is TCP (creating a virtual circuit). Technically, the IP header holds the IP Address, and the protocol on top of IP (UDP or TCP) holds the port number. This makes it possible to have other protocols (eg. ICMP that have no port numbers, but do have IP addressing information).
其他回答
套接字地址是一个IP地址和端口号
123.132.213.231 # IP address
:1234 # port number
123.132.213.231:1234 # socket address
当两个套接字绑定在一起时,就发生了连接。
套接字由三部分组成:
IP地址 传输协议 端口号
端口是1到65535之间的数字,表示设备中的逻辑门。 客户端和服务器之间的每个连接都需要一个惟一的套接字。
例如:
1030为端口。 (10.1.1.2, TCP,端口1030)是一个套接字。
端口:
端口可以指物理连接点 用于外部设备,如串行、并行和USB端口。 术语端口也指某些以太网连接点 如集线器、交换机或路由器上的那些。
套接字:
套接字表示两个网络应用程序之间的单个连接。 这两个应用程序名义上运行在不同的计算机上, 但是套接字也可以用于单台计算机上的进程间通信。 应用程序可以创建多个套接字用于相互通信。 套接字是双向的,这意味着连接的任何一方都能够发送和接收数据。
这个问题已经有了理论上的答案。我想举一个实际的例子来解释这个问题,让大家对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.
端口和插座可以比作银行分行。
“银行”的门牌号与IP地址类似。 银行有不同的部分,比如:
储蓄帐务部 个人贷款部 房屋贷款部 投诉部门
因此,1(储蓄账户部)、2(个人贷款部)、3(住房贷款部)和4(申诉部)是端口。
现在让我们假设你要开一个储蓄账户,你去了银行(IP地址),然后你去了“储蓄账户部门”(端口号1),然后你遇到了在“储蓄账户部门”工作的一名员工。让我们称他为SAVINGACCOUNT_EMPLOYEE1,用于开户。
SAVINGACCOUNT_EMPLOYEE1是套接字描述符,因此可能存在 SAVINGACCOUNT_EMPLOYEE1到SAVINGACCOUNT_EMPLOYEEN。这些都是套接字描述符。
同样地,其他部门将有员工在他们之下工作,他们类似于插座。
推荐文章
- 我可以在/etc/hosts中映射主机名*和端口*吗?
- 如何修改Play执行run命令时使用的默认端口(9000)?
- 连接网络共享时,如何提供用户名和密码
- 如何找到可用的端口?
- 如何通过windows命令行关闭TCP和UDP端口
- UDP和TCP比起来快多少?
- ssh -L转发多个端口
- 一个干净、轻量级的Python扭曲的替代品?
- 套接字的连接超时和读超时之间的区别是什么?
- 将主机端口转发到docker容器
- 远程主机强制关闭现有连接
- TCP连接的最大数据包大小
- connectexception:拒绝连接
- Docker -绑定0.0.0.0:4000失败:端口已经分配
- Node.js中的process.env.PORT是什么?