UDP响应
UDP不发送任何ack回来,但它会发送任何响应吗?
我已经设置了客户端服务器UDP程序。 如果我让客户端将数据发送到不存在的服务器,那么客户端会收到任何响应吗?
我的假设是;
客户端-->广播服务器地址(ARP) 服务器--> 回复客户端的 MAC 地址(ARP) 客户端向服务器发送数据(UDP)
在任何情况下客户端都只会收到 ARP 响应。 如果服务器存在或不存在,它不会收到任何UDP响应?
客户端使用sendto函数发送数据。 sendto调用后我们可以得到错误信息。
所以我的问题是,当客户没有得到任何回复时,如何获取这些信息。 错误代码可以从WSAGetLastError 获取。
我尝试将数据发送到不存在的主机并且 sendto 调用成功。 根据文档,它应该失败并返回值 SOCKET_ERROR。
有什么想法吗??
UDP doesnot sends any ack back, but will it send any response?
I have set up client server UDP program. If I give client to send data to non existent server then will client receive any response?
My assumption is as;
Client -->Broadcast server address (ARP)
Server --> Reply to client with its mac address(ARP)
Client sends data to server (UDP)
In any case Client will only receive ARP response. If server exists or not it will not get any UDP response?
Client is using sendto function to send data. We can get error information after sendto call.
So my question is how this info is available when client doesn't get any response.
Error code can be get from WSAGetLastError.
I tried to send data to non existent host and sendto call succeeded . As per documentation it should fail with return value SOCKET_ERROR.
Any thoughts??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您永远不会收到错误,也不会收到未到达目的地的 UDP 数据包的通知。
You can never receive an error, or notice for a UDP packet that did not reach destination.
sendto
调用没有失败。 数据报已发送到目的地。数据报的接收者或途中的某些路由器可能会返回错误响应(主机无法访问、端口无法访问、超出 TTL)。 但是,当您的系统收到该
sendto
调用时,该调用将成为历史记录。 某些操作系统确实提供了一种方法来找出发生的情况,通常是使用getsockopt
调用。 但是,由于您无论如何都不能依赖于获得错误回复,因为它取决于您无法控制的网络条件,因此通常最好忽略它。位于 UDP 之上的合理协议使用回复。 如果您没有收到回复,则说明另一端没有收到您的数据报,或者回复没有返回给您。
The
sendto
call didn't fail. The datagram was sent to the destination.The recipient of the datagram or some router on the way to it might return an error response (host unreachable, port unreachable, TTL exceeded). But the
sendto
call will be history by the time your system receives it. Some operating systems do provide a way to find out this occurred, often with agetsockopt
call. But since you can't rely on getting an error reply anyway since it depends on network conditions you have no control over, it's generally best to ignore it.Sensible protocols layered on top of UDP use replies. If you don't get a reply, then either the other end didn't get your datagram or the reply didn't make it back to you.
您向其发送数据包的计算机可能会回复 ICMP UDP 端口不可达消息。
The machine to which you're sending packets may reply with an ICMP UDP port unreachable message.
UDP 协议是在IP 之上实现的。 您将 UDP 数据包发送到由 IP 地址(而不是 MAC 地址)标识的主机。
正如所指出的,UDP 本身不会发送回复,您必须自己添加代码来执行此操作。 然后,您将必须添加代码以期待回复,并在响应丢失时采取适当的操作(通常在计时器上重新发送,直到您确定另一端“死机”),等等。
The UDP protocol is implemented on top of IP. You send UDP packets to hosts identified by IP addresses, not MAC addresses.
And as pointed out, UDP itself will not send a reply, you will have to add code to do that yourself. Then you will have to add code to expect the reply, and take the proper action if the response is lost (typically resend on a timer, until you decide the other end is "dead"), and so on.
如果您在订购或验证时需要可靠的 UDP,那么 TCP/IP 将为您提供 RUDP 或可靠 UDP 的选择。 有时您确实需要验证,但 UDP 和 TCP 的混合可能会阻碍 TCP 的可靠性,从而导致瓶颈。
对于大多数大型 MMO 来说,例如 UDP 和可靠性 UDP 是通信和可靠性的手段。 RUDP 所做的只是添加一小部分 TCP/IP 来验证和排序某些消息(但不是全部)。
常见的游戏开发网络库是 Raknet,它内置了该库。
RUDP
http://www.javvin.com/protocolRUDP.html
使用 Raknet 和的 RUDP 示例Python
http://pyraknet.slowchop.com/
If you need reliable UDP as in ordering or verification such that TCP/IP will give you take a look at RUDP or Reliable UDP. Sometimes you do need verification but a mixture of UDP and TCP can be held up on the TCP reliability causing a bottleneck.
For most large scale MMO's for isntance UDP and Reliablity UDP are the means of communication and reliability. All RUDP does is add a smaller portion of TCP/IP to validate and order certain messages but not all.
A common game development networking library is Raknet which has this built in.
RUDP
http://www.javvin.com/protocolRUDP.html
An example of RUDP using Raknet and Python
http://pyraknet.slowchop.com/