我认为这是很容易理解的。IP地址就像电话号码。端口就像一个电话扩展。UDP包就像一个短信(SMS)。TCP连接就像一个电话呼叫。IP地址标识你的PIC在网络上。你可能只有一个本地IP地址在你的PIC(所以有)。没有多少选择。由于您可能有许多任务,所以您可以使用端口号来区分不同的任务——与业务可能拥有单个电话号码相同的方式,然后使用扩展来区分工人。您可以将UDP消息从任何地方发送到网络上的任何地方。对于UDP,没有服务器或客户端,只是对等体——就像在移动电话网络上传递文本消息一样。套接字不是物理实体。它们不存在于网络上,对外部词不可见。它们是软件实体——最有可能的框架中的数据结构,用于管理TCP/IP包。当打开服务器UDP套接字时,您会对框架说:“嘿,为我创建一个套接字。这里有我的电话号码(本地IP地址)和扩展(本地端口),如果有文本的话。SSAGE(UDP包)到达指定的地址,我想看到它。框架会说你正在听指定的“IP地址:端口”。当一个UDP数据包到来时,框架将数据包传递给任何正在监听它的人(如果有的话)。请注意,当打开套接字时,物理字中不会发生任何事情。发生的唯一事情就是为你看数据包的框架。当你打开一个客户端UDP套接字时,你会对框架说:“嘿,我要把文本消息(UDP包)发送到这个电话号码(远程IP地址)和扩展(远程端口)。我也想看到所有的文本消息(UDP包),将在回应“回来”。该框架将默默地将电话号码(本地IP地址)和扩展(本地端口)分配给您的套接字,这样当您发送某些东西时,就有可能做出响应。
以上来自于百度翻译
以下为原文
I think it's very easy to understand by analogy.
IP address is like phone number.
Port is like a phone extension.
UDP packet is like a text (SMS) message.
TCP connection is like a phone call.
IP address identifies your PIC on the network. You probably have only one local IP address on your PIC (so there's not much choice ). Since you may have many tasks, you use port numbers to distinguish between different tasks - same way as a business may have a single phone number and then use extensions to distinguish between workers.
You can send UDP messages from anywhere to anywhere on the network. For UDP, there's no servers or clients, just peers - same as passing text messages on the mobile phone networks.
Sockets are not physical entities. They don't exist on network and are not visible to outside word. They're software entities - most likely data structures in the framework which are used by it to manage TCP/IP packets.
When you open a server UDP socket, you say to the framework: "Hey, create a socket for me - here's my phone number (local IP address) and extension(local port), if there's a text message (UDP packet) coming to the specified address, I want to see it". Framework would say that you're listening on the specified "IP address:port". When a UDP packet comes, the framework passes the packet to whoever is listening for it, if any. Note that when you open a socket nothing happens in the physical word. The only thing that happens is framework watching for packets for you.
When you open a client UDP socket, you say to the framework: "Hey, I'm going to send text messages (UDP packets) to this phone number(remote IP address) and extension(remote port). I also want to see all the text messages (UDP packets) which will come back in response". The framework will silently assign a phone number (local IP address) and extension (local port) to your socket, so that when you send something, it would be possible to respond.