RakNet 客户端与服务器 启动 区别之 RakNet::SocketDescriptor()
2013-12-16 00:10
387 查看
的确是用来绑定IP和端口号的,测试过程如下:
本机ip:172.16.30.47
朋友ip:172.16.30.38
(1) 客户端和服务端都在本机,客户端绑定了本机ip和端口,结果收不到数据。
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(SERVER_PORT,"172.16.30.47"),1);服务端设置
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
原因:端口被占用
(2) 客户端和服务端都在本机,客户端绑定了本机ip、但是没有绑定端口,一切ok
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(0,"172.16.30.47"),1);服务端设置:
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
(3) 服务端在本机(47),客户端在朋友电脑(38)。客户端绑定我的ip(47)
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(0,"172.16.30.47"),1);
服务端设置:
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
服务端收不到数据,因为绑定的ip与本机ip不符合
(4) 服务端在本机(47),客户端在朋友电脑(38)。客户端绑定朋友的ip(38)
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(0,"172.16.30.38"),1);服务端设置:
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
一切ok。
-----------------------------------------------------------------------------------------------------------------------
初步估计是用来绑定ip和端口号的,明天再看。。。。
----------------------------------------------------------------------------------------------------------------------------
刚才测试的时候,服务器收不到数据。
和例子代码对比看,发现 客户端使用了服务器的一个参数
例子代码中,Startup第二个参数是
至于为什么……我也不知道。。求各位路过大婶解答。
下面是客户端和服务器的启动代码。
本机ip:172.16.30.47
朋友ip:172.16.30.38
(1) 客户端和服务端都在本机,客户端绑定了本机ip和端口,结果收不到数据。
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(SERVER_PORT,"172.16.30.47"),1);服务端设置
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
原因:端口被占用
(2) 客户端和服务端都在本机,客户端绑定了本机ip、但是没有绑定端口,一切ok
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(0,"172.16.30.47"),1);服务端设置:
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
(3) 服务端在本机(47),客户端在朋友电脑(38)。客户端绑定我的ip(47)
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(0,"172.16.30.47"),1);
服务端设置:
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
服务端收不到数据,因为绑定的ip与本机ip不符合
(4) 服务端在本机(47),客户端在朋友电脑(38)。客户端绑定朋友的ip(38)
客户端设置:
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(0,"172.16.30.38"),1);服务端设置:
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
一切ok。
-----------------------------------------------------------------------------------------------------------------------
初步估计是用来绑定ip和端口号的,明天再看。。。。
----------------------------------------------------------------------------------------------------------------------------
刚才测试的时候,服务器收不到数据。
和例子代码对比看,发现 客户端使用了服务器的一个参数
m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1);
例子代码中,Startup第二个参数是
m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(),1);
至于为什么……我也不知道。。求各位路过大婶解答。
下面是客户端和服务器的启动代码。
bool clientStart(std::string ipAddrStr,std::string passwdStr) { //start raknet network connect if (m_pRakpeerInterface==nullptr) { std::cout<<"(client) m_pRakpeerInterface is null"<<std::endl;; } m_pRakpeerInterface->Startup(1,&RakNet::SocketDescriptor(),1); RakNet::ConnectionAttemptResult res= m_pRakpeerInterface->Connect(ipAddrStr.c_str(), SERVER_PORT, passwdStr.c_str(), passwdStr.length()); m_targetAddress=RakNet::SystemAddress(ipAddrStr.c_str(),SERVER_PORT); return res==RakNet::CONNECTION_ATTEMPT_STARTED; } void serverStart(std::string passwdStr) { //start raknet network connect if (m_pRakpeerInterface==nullptr) { std::cout<<"(server) m_pRakpeerInterface is null"<<std::endl;; } m_pRakpeerInterface->SetIncomingPassword(passwdStr.c_str(),passwdStr.length()); //start m_pRakpeerInterface->Startup(MAX_CLIENTS,&RakNet::SocketDescriptor(SERVER_PORT,0),1); m_pRakpeerInterface->SetMaximumIncomingConnections(MAX_CLIENTS); }
相关文章推荐
- Maven 安装步骤
- 垃圾回收机制
- JavaScript Window History 浏览器的历史
- 9i exp/imp 按照用户导出用户下对象到其他数据库
- 新起点
- [POJ2104]K-th Number
- javascript初学者记录--定义类或对象
- 给Mac设置定时关机、重启、睡眠
- C# Type Basics
- 自定义ListView实现底部动画更新item
- 服务器(VPS)安装WebSite Panel面板教程(图文)
- 用U盘与移动硬盘制作WIN7启动盘(亲自实践)
- Java IO流
- spark介绍
- Windows Azure 安全最佳实践 - 第 3 部分:确定安全框架
- Windows Azure 安全最佳实践 - 第 3 部分:确定安全框架
- Windows Azure 安全最佳实践 - 第 3 部分:确定安全框架
- Windows Azure 安全最佳实践 - 第 3 部分:确定安全框架
- Java 第二天
- 嵌入式C开发人员的最好的0x10道笔试题