通过 UDP 接收响应 [英] Receiving a response through UDP

查看:32
本文介绍了通过 UDP 接收响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到应用程序通过 UDP 将数据包发送到某个端口上的 IP 并接收响应.响应去哪个端口?(顺便说一句,如果没有端口转发到我的 PC,路由器怎么知道响应是针对我的 PC 的?)

I have seen applications send a packet through UDP to an IP on some port and receiving a response. Which port does the response go to? (Btw, how can the router know that the response is for my PC, if there are no ports forwarded to my PC?)

你好,Neo_b

推荐答案

分配给响应的端口取决于应用程序.UDP 是完全无状态的,因此在触发数据包后,应用程序可以期待响应的唯一方式是它是否知道另一端将要发送一个.根据 UDP 应用程序的不同,为了简单起见,我希望响应会出现在同一端口上——对于像 TCP 这样的协议来说,情况并非如此,因为它有一个故意随机(且高)的源端口.

What port a response is assigned is up to the application. UDP is completely stateless, so after firing off a packet the only way an application can expect a response is if it knows the other end is going to send one. Depending on the UDP application, I'd expect that the response would come on the same port for simplicity -- this is not the case for protocols like TCP, which have an intentionally random (and high) source port.

要回答您的第二个问题,许多路由器,甚至是廉价的家用路由器,都会执行状态数据包检查(SPI).像这样的事情可能会发生,但如果我离开,我会得到纠正:

To answer your second question, many routers, even inexpensive home routers, do stateful packet inspection (SPI). Something like this likely happens, but I'm up for being corrected if I'm off:

[设置客户端、路由器、互联网、服务器.]

  1. 客户端发出 UDP 数据包.
  2. 路由器将 UDP 数据包传递到 Internet.
  3. 路由器记住客户端向服务器发送了 UDP 数据包,并在其内存中建立映射.
  4. 服务器发送一个 UDP 数据包,可能在同一端口上.
  5. 路由器接收数据包,并检查映射以查找最近与服务器通信的客户端.
  6. 路由器将数据包传递给客户端.

这是特定于路由器的,我想,但这是我对其工作原理的理解.

How this is implemented is specific to the router, I'd imagine, but that's my understanding of how it works.

这篇关于通过 UDP 接收响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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