在广域网的TCP和UDP套接字服务器 [英] TCP and UDP Socket Server on a WAN

查看:327
本文介绍了在广域网的TCP和UDP套接字服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个服务器和客户端,它利用TCP和UDP。服务器非常适用于局域网的设置,但是当通过广域网传输不被接收UDP消息。我相信这是因为用于发送数据的UDP套接字未在NAT表中剩余的足够长的时间返回任何信息。有没有办法要么使UDP端口留在路由器上打开(无端口转发),或使用UDP的相同的端口已连接的TCP连接?先谢谢了。

I am attempting to create a server and client that utilizes both TCP and UDP. The server works very well in a LAN setting but the UDP messages are not being received when transmitted over a WAN. I believe it is because the UDP socket used to send the data is not remaining in the NAT tables long enough to return any information. Is there a way to either make the UDP port stay open in the router (without port forwarding) or use the same port for UDP as the already connected TCP connection? Thanks in advance.

推荐答案

如果你没有得到它可能只是被防火墙阻止任何流量。在这种情况下,它不是关于转发,它是如何打开的端口。

If you're not getting any traffic it is probably simply blocked by the firewall. In this case it is not about forwarding, it is about opening the port.

大多数(如果不是全部)的NAT /防火墙设备将允许在两个方向上一次一个UDP通信孔是通过NAT打孔。也就是说,如果我的笔记本电脑在这里,坐在NAT /防火墙后面,发送一个UDP数据包发送到Internet我的NAT /防火墙将通过允许返回UDP流量的源端口号。记住我工作了很多UDP和我的经验是,这是法治和极少数的例外。

Most (if not all) NAT/Firewall devices will allow UDP traffic in both directions once a hole is punched through the NAT. That is, if my laptop here, sitting behind a NAT/firewall, sends a UDP packet out to the Internet my NAT/firewall will allow return UDP traffic to the originating port number through. I work a lot with UDP and my experience is that this is the rule and very few exceptions.

请虽然不能保证UDP数据包交付。

Keep in mind though UDP packets are not guaranteed to be delivered.

在NAT你的客户?是否有任何数据包的客户端发送到服务器?在服务器端到客户端方向的问题?

Is your client behind a NAT? Do any packets the client send get to the server? Is the problem in the server to client direction?

如果您使用相同的端口号为UDP和TCP这是不会改变的情况。你不能一个TCP连接上搭载,因为它是一个不同的协议。

If you use the same port number for UDP and TCP this will not change the situation. You can't piggyback on a TCP connection because it is a different protocol.

网络地址转换(NAT)单播UDP 行为要求

http://en.wikipedia.org/wiki/UDP_hole_punching

这篇关于在广域网的TCP和UDP套接字服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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