udp穿越nat

bluesoalr 2004-03-30 10:27:13
服务器有公网IP,客户端在私网,通过NAT连到服务器。
服务器(eg:221.202.121.25 port:8000)能够接收客户端(eg:192.168.1.7 port:9000)发来的udp数据
服务器根据recvfrom返回的对方地址(eg:202.186.5.5 port:46521)信息,向这个地址(202.186.5.5 port:46521)发送数据,结果客户端没有收到任何数据。整个试验过程中所有地址(包括端口)都没有变化,所有机器也都没有开防火墙。

请问,如何才能使私网内的客户端能够收到服务器的数据?

如果可行,我可以给800分。
...全文
108 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxq80 2004-04-12
  • 打赏
  • 举报
回复
mark
endicking 2004-04-11
  • 打赏
  • 举报
回复
根据端口不同来判断客户子机
cdchun 2004-04-10
  • 打赏
  • 举报
回复
顶。
zxq80 2004-04-08
  • 打赏
  • 举报
回复
up
EricKong 2004-04-08
  • 打赏
  • 举报
回复
( 转贴)nat的几种类型
The four types defined in [6] are:

Full Cone: A full cone NAT is one where all requests from the
same internal IP address and port are mapped to the same
external IP address and port. Furthermore, any external
host can send a packet to the internal host, by sending a
packet to the mapped external address.

Restricted Cone: A restricted cone NAT is one where all requests
from the same internal IP address and port are mapped to
the same external IP address and port. Unlike a full cone
NAT, an external host (with IP address X) can send a packet
to the internal host only if the internal host had
previously sent a packet to IP address X.

Port Restricted Cone: A port restricted cone NAT is like a
restricted cone NAT, but the restriction includes port
numbers. Specifically, an external host can send a packet,
with source IP address X and source port P, to the internal
host only if the internal host had previously sent a packet
to IP address X and port P.
Symmetric: A symmetric NAT is one where all requests from the
same internal IP address and port, to a specific
destination IP address and port, are mapped to the same
external IP address and port. If the same host sends a
packet with the same source port, but to a different
destination, a different mapping is used. Furthermore, only
the external host that receives a packet can send a UDP
packet back to the internal host.

关键看你的nat
extractman 2004-04-07
  • 打赏
  • 举报
回复
BCB从0号开始,VC从500号开始.
extractman 2004-04-07
  • 打赏
  • 举报
回复
上述问题在下面进行:
http://expert.csdn.net/Expert/TopicView1.asp?id=2936688
http://expert.csdn.net/Expert/TopicView1.asp?id=2936686
extractman 2004-04-07
  • 打赏
  • 举报
回复
##集体攻关! 穿越NAT,分别躲在不同的内网的计算机进行UDP通讯##

假设跟进的爱好者在x楼,那么他/她的编号是x.如果x为奇数,则假设为A,如果为偶数假设为B,A所在的连接Internet的NAT服务器假设为AS,而对应B的就是BS.目标就是:
A-->AS-->BS-->B
B-->BS-->AS-->A
进行通讯。

现在,大家通过http://bizflash.net/bbsserverip.txt获得服务器的地址,然后向该地址的555端口发送WORD类型(2字节)的整数,就是你所在的楼层x,服务器会返回相邻的楼层的IP及端口信息:例如1楼的会返回1、2楼的ip,port;2楼的会返回1、2楼的ip,port;3楼的会返回3、4楼的ip,port,依此类推。

下面是BCB的代码,至于VC也差不多,请参考:
struct IpData
{
char ip[18];
WORD port;
};
void __fastcall TForm1::IdUDPServer1UDPRead(TObject *Sender,
TStream *AData, TIdSocketHandle *ABinding)
{
IpData *data;

data=(IpData *)((TMemoryStream *)AData)->Memory;
Memo1->Lines->Add(data[0].ip);
Memo1->Lines->Add(data[0].port);
Memo1->Lines->Add(data[1].ip);
Memo1->Lines->Add(data[1].port);
}
//----------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WORD s=Edit1->Text.ToInt();//我是第几楼?
AnsiString ip=Edit2->Text;//从http://bizflash.net/bbsserverip.txt获得
IdUDPServer1->SendBuffer(ip,555,&s,sizeof(s));
}
//---------------------------------

都知道了对方的ip,port后,大家就有了攻关的基础了,请爱好者都留下合适的交流手段,例如EMail,尤其是相邻的楼层的更要频繁交流。

如果攻破了,别忘了在这里进行公布!
bluesoalr 2004-04-07
  • 打赏
  • 举报
回复
但这样也有不爽的地方:
两个都在内网的客户端不能直接通信,只能通过服务器中转
效率很低,
bluesoalr 2004-04-06
  • 打赏
  • 举报
回复
搞定
用接收数据的那个套结字发送就可以了
ricky460 2004-04-06
  • 打赏
  • 举报
回复
mark
kufan 2004-04-06
  • 打赏
  • 举报
回复
up
yesry 2004-04-06
  • 打赏
  • 举报
回复
关注。
Hawk_lp 2004-04-04
  • 打赏
  • 举报
回复
up
sharkhuang 2004-04-04
  • 打赏
  • 举报
回复
nat的udp端口有个老化时间!如果你的svr-->client的包很长时间返回,估计已经老化了!就不通了
summax 2004-04-04
  • 打赏
  • 举报
回复
不是客户端做.是网关要做一个端口映射到客户端的接收端口.
djgfhd 2004-04-04
  • 打赏
  • 举报
回复
MARK
xrenwu 2004-04-04
  • 打赏
  • 举报
回复
严重关注中
bluesoalr 2004-04-03
  • 打赏
  • 举报
回复
我用抓包工具看了,就是202.168.1.102:1434 没有把数据转发给A.

客户端怎么做端口映射?
谢谢!

xghost 2004-04-02
  • 打赏
  • 举报
回复
客户端是不是忘了端口映射?
加载更多回复(16)

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧