[英]udp packet not coming through
I have the following setup: 我有以下设置:
Dedicated server --> Internet --> Modem (telenet) --> Router --> client 专用服务器-> Internet->调制解调器(telenet)->路由器->客户端
The problem is that I'm not receiving any packets.. Is my scenario possible, what should I do? 问题是我没有收到任何数据包。我的情况是否可行,我该怎么办?
Requirements: 要求:
Greets Daan & thanks in advance 问候大安,并提前致谢
EDIT: 编辑:
Code example from server: 来自服务器的代码示例:
UdpClient udpSender = new UdpClient();
IPEndPoint localServerGateway = new IPEndPoint(IPAddress.Parse(externalIp), 8003);
string message = "testmessage";
byte[] messageBytes = Encoding.ASCII.GetBytes(message);
try
{
udpSender.Send(messageBytes, messageBytes.Length, localServerGateway);
}
catch (Exception error)
{
Console.WriteLine("Error while sending message: " + error.ToString());
}
udpSender.Close();
Code example from client: 客户端代码示例:
private void listenForMasterSyncRequest()
{
bool done = false;
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 8003);
try
{
while (!done)
{
byte[] bytes = masterSyncUdpListener.Receive(ref groupEP);
handleMessage(bytes, bytes.Length, true); // handles incoming messages, this is never reached because no packets are received :-(
}
}
catch (Exception e)
{
Console.WriteLine("An error occured while listening to server broadcast updates: " + e.ToString());
}
finally
{
masterSyncUdpListener.Close();
}
}
NAT works by setting up sessions between external and internal hosts. NAT通过在外部主机和内部主机之间建立会话来工作。 But the session must be initiated on the internal side, and in your case that's the client side.
但是会话必须在内部启动,在您的情况下,这是客户端。 So the way it has to work is that the client has to poll the server, sending a UDP packet to a particular port on the server asking if a sync is needed.
因此,它的工作方式是客户端必须轮询服务器,将UDP数据包发送到服务器上的特定端口,询问是否需要同步。 The server must send a UDP response from that same port back to the same port the client sent the original request.
服务器必须将UDP响应从同一端口发送回客户端发送原始请求的同一端口。 If you do it this way packets from the server will get through, otherwise they will not.
如果以这种方式执行此操作,则来自服务器的数据包将通过,否则将无法通过。 I know this works because this is exactly how DNS lookups work from behind NAT.
我知道这可行,因为这正是从NAT后面进行DNS查找的方式。
由于您无法控制路径中的NAT设备,因此这里唯一明智的方法是使用TCP作为主要传输方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.