C ++打孔UDP(RTP) [英] c++ Hole punching UDP(RTP)

查看:111
本文介绍了C ++打孔UDP(RTP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个客户端-服务器语音聊天程序(非托管C ++,win32),其中客户端使用TCP连接到服务器,并且文本聊天/聊天室功能在TCP中完成,而所有音频传输均通过单独的UDP/RTP套接字发送(使用JRTPLIB的API).

I am doing a client-server voice chat program(unmanaged C++,win32) in which clients connects to the server using TCP and textchat/chatroom functions are done in TCP while all audiotransmission is sent through a separate UDP/RTP socket (using the API from JRTPLIB).

因此从TCP连接中可以知道IP,并且可以在建立连接后发送RTP套接字的端口号.

So the IP is known from the TCP connection, and the port number of the RTP socket can be sent after connection is established.

问题是自建立连接以来,在TCP中仅服务器需要进行端口转发以使通信同时起作用,而在UDP中则必须使用recvfrom()- afaik需要将端口设置为首先在客户端上打开,我不需要(如果您查看任何多人游戏或VoIP客户端,则不需要)

The problem is that in TCP only the server needs to do port forwarding for communications to work both ways since you establish a connection, while in UDP you'd have to use recvfrom() -- which afaik needs the ports to be opened in the first place on the client side, which I do not want (and is not needed if you look at any multiplayer game or VoIP client)

阅读有关UDP打孔的资料(例如 http://en.wikipedia.org/wiki/UDP_hole_punching ),例如,他们不断提到与服务器进行udp对话.就是这样-您实际上如何与服务器启动udp对话(双向)而无需客户端打开任何端口?如前所述,在TCP中,您只需要将connect()连接到服务器即可,并且双向通信都是可能的.

Reading on sources that talk about UDP Hole Punching (for example http://en.wikipedia.org/wiki/UDP_hole_punching) for example they keep mentioning starting a udp conversation with the server. That's the thing - how do you actually start a udp conversation(both ways) with the server without the client having to open any ports? in TCP as I mentioned you just need to connect() to the server and communication is possible both ways.

此外-我知道RTP是基于UDP构建的,但是关于RTP穿孔(再次使用JRTPLIB),它是否与UDP不同,我是否应该了解其他内容?

Also -- I know RTP builds on UDP but is there anything else I should know about the RTP hole punching (again, using JRTPLIB) that makes it differ from UDP?

提前谢谢!

推荐答案

打开端口"有两种可能的定义.一种是使用bind()用于UDP或listen()用于TCP打开端口,另一种是在防火墙中打开端口.

There are two possible definitions of "opening a port". One is opening a port with bind() for UDP or listen() for TCP, another one is opening a port in a firewall.

您需要使用API​​调用打开端口才能接收某些信息,但无法解决,但是您可能意识到了这一点,所以我认为您的意思是在防火墙中打开端口.但是您不需要在发起通信的那一侧(客户端)上执行此操作.这适用于TCP和UDP,除非您的防火墙设置为非常偏执的模式.如果某个时间之前有数据报从该端口发送到同一服务器,则任何合理的防火墙都将允许该服务器对UDP端口做出响应.仅当双方都在NAT防火墙/路由器NAT之后时才需要打孔.这就是Skype做到的方式.

You need to open a port with an API call in order to receive something, there is no way around it, but you probably realize this, so I think you mean opening a port in a firewall. But you don't need to do this on the side that initiates communication (the client). This applies both to TCP and UDP, unless your firewall is set up in a very paranoid mode. Any reasonable firewall would allow a response from a server to a UDP port if there was a datagram sent from this port to the same server some time before. You only need hole punching if both sides are behind NATing firewalls/routers. That's how Skype does it.

此外,您甚至不必理会recvfrom()之类的东西.您可以只绑定()一个UDP套接字,然后完全按照与TCP相同的方式使用connect()和recv()/send()或read()/write().

Moreover, you don't even have to bother with recvfrom() and such stuff. You can just bind() a UDP socket, then use connect() and recv()/send() or read()/write() exactly in the same way as you'd do with TCP.

这篇关于C ++打孔UDP(RTP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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