主要思想就是2个
服务器转发和NAT穿透。一般来说都会使用服务器转发,在传输文件的时候可以用NAT穿透,来缓解服务器的压力。
你在这里只能求思路,转发服务器是个大家伙,不是几行代码就搞的定的。
路由器的端口号与你机器的端口号是不一样的(你做了端口映射,对方没有,他接收不到)可以有个中间服务器,对方电脑先与服务器通信(告知Ip和端口),你与服务器通信(获取对方的Ip和端口),也就是NAT穿透;路由端如何支持UPNP协议的话,应该不需要做端口映射;你可以看看UPNP协议//bool tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port )//失败 没指定 是IPV4还是IPV6
// QString string("192.168.112.10")
// QHostAddress address(QHostAddress::LocalHost)//QHostAddress::Any
// bool tf =address.setAddress( string )
// tf =m_pSocket->bind(address,m_port )//失败
// quint32 ip4Add = 192<<24|168<<16|112<<8|10
// QHostAddress address(QHostAddress::Any)//QHostAddress::LocalHost
// address.setAddress( ip4Add )
// bool tf =m_pSocket->bind(address,m_port )//失败
//quint32 ip4Add = 192<<24|168<<16|112<<8|100
//bool tf =m_pSocket->bind(QHostAddress(ip4Add),m_port,QAbstractSocket::ShareAddress )
//tf =m_pSocket->bind(QHostAddress(ip4Add),m_port,QAbstractSocket::ReuseAddressHint| QAbstractSocket::ShareAddress | QAbstractSocket::DontShareAddress )
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ReuseAddressHint| QAbstractSocket::ShareAddress | QAbstractSocket::DontShareAddress )//失败
// tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ReuseAddressHint )
// tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ShareAddress )
// tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::DontShareAddress )
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ReuseAddressHint | QAbstractSocket::ShareAddress )
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::DontShareAddress | QAbstractSocket::ReuseAddressHint )
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::DontShareAddress | QAbstractSocket::ShareAddress )
//m_pSocket->bind(QHostAddress::Any, m_port )//方便使用
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)