UDP 响应未返回客户端 [英] UDP response not reaching back client

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

问题描述

我正在开发一个应用程序,它发送 UDP 数据包以启动处理,需要在 3-5 分钟后在同一个套接字上发回响应,但问题是当响应被发回时,它永远不会到达客户端.我正在使用Java.有什么建议,我们如何让套接字在更长的时间内保持活动状态?

I am working on a application which sends UDP packet to initiate a Processing and needs to send back response on same socket after 3-5 minutes, but issue is that when response is sent back, it never reaches client. I am using java. Any suggestions, how we can keep the socket alive over longer period of time?

--

推荐答案

有什么建议,我们如何让套接字在更长的时间内保持活动状态?

Any suggestions, how we can keep the socket alive over longer period of time?

有没有办法设置UDP超时设置...?

Is there a way to set UDP timeout setting ...?

UDP 是无连接的.如果应用程序绑定到 UDP 服务器套接字并进行侦听,则它可以无限期地等待消息到达.

UDP is connectionless. If an application binds to a UDP server-socket and listens, it can wait for messages to arrive indefinitely.

另一方面,无法在协议/套接字级别检测丢失的 UDP 消息.如果一台机器向另一台机器发送 UDP 消息,第一台机器无法直接知道消息是否到达?没有传输级别超时来告诉发送方重新传输.

The flipside is that there is no way to detect a lost UDP message at the protocol / socket level. If one machine sends a UDP message to another one, the first machine has no direct way of knowing if the message has arrived or not? There are no transport level timeouts to tell the sender to retransmit.

如果您需要可靠性、超时、自动重传等,最好使用基于连接的传输协议,例如 TCP.

If you need reliability, timeouts, automatic retransmission, etc, you are better of using a connection-based transport protocol such as TCP.

一个同事建议的问题,可能是防火墙在一段时间内没有活动时关闭UDP连接,为了保证通信可靠,需要实现超时探测.

Issue as suggested by a colleague, might be that firewall closes UDP connections if there is no activity for certain period of time, for communication to be reliable one need to implement timeout probe.

从表面上看,这种解释是荒谬的.UDP 是无连接的,因此没有要关闭或保持活动的连接.

On the face of it, that explanation is nonsensical. UDP is connectionless, so there is no connection to close, or to keep alive.

真正的解释可能是以下之一:

The real explanation is likely to be one of the following:

  • UDP 请求或 UDP 回复被一台或另一台机器上或网络中某处的防火墙软件阻止.

  • The UDP requests or the UDP replies are being blocked by firewall software on one or other of the machines, or somewhere in the network.

发送或接收消息的方式有问题.

Something is not right about the way that the messages are being sent or received.

您正在尝试通过 NAT 网关发送 UDP 消息;例如到其 IP 地址无法从另一台路由的机器.需要UDP打洞等特殊措施来将UDP流量传输到NATed主机,并且可能需要发送保持活动的数据包以防止UDP 漏洞"超时.

You are trying to send UDP messages through a NAT gateway; e.g. to a machine whose IP address cannot be routed from the other. Special measures such as UDP hole punching are required to get UDP traffic to a NATed host, and it may be necessary to send keep-alive packets to keep a "UDP hole" from timing out.

如果您尝试通过 Java 的 NAT 防火墙发送 UDP,则有多种(第 3 方)Java 库可以执行此操作.搜索stun"和turn"或ice"以及java"和udp",或阅读以下内容以获取开始:

If you are trying to send UDP through a NAT firewall from Java, there are various (3rd-party) Java libraries for doing this. Search for "stun" and "turn" or "ice" together with "java" and "udp", or read the following for a started:

这些解决方案都要求您采取措施刷新"NAT 绑定,以保持防火墙漏洞"打开.

These solutions all require you to take steps to "refresh" the NAT bindings to keep the firewall "hole" open.

这篇关于UDP 响应未返回客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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