简体   繁体   English

C ++ Windows32 Winsock UDP路由?

[英]C++ windows32 winsock UDP routing?

In C++ using Windows32 using windows socket library using UDP is there a way to give a client routing information to another client to establish a connection between clients without having to route through the server 在使用Windows32的C ++和使用UDP的Windows套接字库中,有一种方法可以将客户端路由信息提供给另一个客户端以在客户端之间建立连接,而不必通过服务器进行路由

Clarification: 澄清:

server - waits for computers and gives routing info - a detached server client - sends a ack request and waits for routing info - a normal user computer 服务器-等待计算机并提供路由信息-分离的服务器客户端-发送确认请求并等待路由信息-普通用户计算机

but ok so its not posible to give routing info to clients to interconnect clients without requiring the data to be forwarded through the server? 但是好吧,这样就不可能在不要求数据通过服务器转发的情况下将路由信息提供给客户端以互连客户端吗?

Short answer: no. 简短的回答:不。

Long answer: No matter what information you include in your UDP packet, at the transport layer it's just another IP packet, and your NIC will slap the appropriate headers on it and send it on its way. 长答案:无论您在UDP数据包中包含什么信息,在传输层它都是另一个IP数据包,并且NIC会在其上拍上适当的标头并按其方式发送。 Unless the hosts are directly connected to each other, the network topology will dictate how many hops (routers/switches) it has to make to get there. 除非主机直接相互连接,否则网络拓扑将决定到达该主机必须经过多少跳(路由器/交换机)。

Addendum: 附录:

I'm not sure what you mean by server (I read it as "router" initially, but you could just as easily have been talking about a Domain Name Server (DNS)). 我不确定您所说的服务器是什么意思(起初我将其读为“路由器”,但您谈论域名服务器(DNS)可能同样容易)。 If you are trying to avoid DNS lookup, you can easily do this by providing an IP address directly (assuming you know it). 如果您尝试避免DNS查找,则可以通过直接提供IP地址(假设您知道)来轻松地做到这一点。 However, DNS lookup is a one-time process--once the IP address is known, the DNS host is not involved in routing your UDP packets in any way. 但是,DNS查找是一次性的过程-一旦知道IP地址,DNS主机就不会以任何方式参与UDP数据包的路由。

Short answer: no 简短答案:否

Long answer: yes --- but you have to use IPPROTO_IP, not IPPROTO_UDP. 长答案:是---但是您必须使用IPPROTO_IP,而不是IPPROTO_UDP。 Use IP_OPTIONS option in setsockopt() to set source routing . 在setsockopt()中使用IP_OPTIONS选项设置源路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM