本文整理汇总了C++中SystemAddress::SetBinaryAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ SystemAddress::SetBinaryAddress方法的具体用法?C++ SystemAddress::SetBinaryAddress怎么用?C++ SystemAddress::SetBinaryAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SystemAddress
的用法示例。
在下文中一共展示了SystemAddress::SetBinaryAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Connect
bool NatPunchthrough::Connect(const char* destination, unsigned short remotePort, const char *passwordData, int passwordDataLength, SystemAddress facilitator)
{
SystemAddress systemAddress;
systemAddress.SetBinaryAddress(destination);
systemAddress.port=remotePort;
return Connect(systemAddress, passwordData, passwordDataLength, facilitator);
}
示例2: WaitAndConnect
bool CommonFunctions::WaitAndConnect(RakPeerInterface *peer,char* ip,unsigned short int port,int millisecondsToWait)
{
SystemAddress connectToAddress;
connectToAddress.SetBinaryAddress(ip);
connectToAddress.port=port;
TimeMS entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (peer,connectToAddress,true)&&GetTimeMS()-entryTime<millisecondsToWait)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (peer,connectToAddress,true,true,true,true))
{
peer->Connect(ip,port,0,0);
}
RakSleep(100);
}
if (ConnectionStateMatchesOptions (peer,connectToAddress,true))
{
return 1;
}
return 0;
}
示例3: DisconnectAndWait
void CommonFunctions::DisconnectAndWait(RakPeerInterface *peer,char* ip,unsigned short int port)
{
SystemAddress targetAddress;
targetAddress.SetBinaryAddress(ip);
targetAddress.port=port;
while(CommonFunctions::ConnectionStateMatchesOptions (peer,targetAddress,true,true,true,true))//disconnect client
{
peer->CloseConnection (targetAddress,true,0,LOW_PRIORITY);
}
}
示例4: WaitForConnectionRequestsToComplete
void ManyClientsOneServerDeallocateBlockingTest::WaitForConnectionRequestsToComplete(RakPeerInterface **clientList, int clientNum, bool isVerbose)
{
SystemAddress currentSystem;
bool msgWasPrinted=false;
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
while (clientList[i]->IsConnectionAttemptPending (currentSystem) )
{
if (msgWasPrinted==false)
{
printf("Waiting for connection requests to complete.\n");
msgWasPrinted=true;
}
RakSleep(30);
}
}
}
示例5: WaitForConnectionRequestsToComplete
void ManyClientsOneServerBlockingTest::WaitForConnectionRequestsToComplete(RakPeerInterface **clientList, int clientNum, bool isVerbose)
{
SystemAddress currentSystem;
bool msgWasPrinted=false;
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
while (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,true,true) )
{
if (msgWasPrinted==false)
{
printf("Waiting for connection requests to complete.\n");
msgWasPrinted=true;
}
RakSleep(30);
}
}
}
示例6: RunTest
/*
Description:
Tests:
virtual void RakPeerInterface::AddToSecurityExceptionList ( const char * ip )
virtual void RakPeerInterface::AddToBanList ( const char * IP, TimeMS milliseconds = 0 )
virtual void RakPeerInterface::GetIncomingPassword ( char * passwordData, int * passwordDataLength )
virtual void RakPeerInterface::InitializeSecurity ( const char * pubKeyE, const char * pubKeyN, const char * privKeyP, const char * privKeyQ )
virtual bool RakPeerInterface::IsBanned ( const char * IP )
virtual bool RakPeerInterface::IsInSecurityExceptionList ( const char * ip )
virtual void RakPeerInterface::RemoveFromSecurityExceptionList ( const char * ip )
virtual void RakPeerInterface::RemoveFromBanList ( const char * IP )
virtual void RakPeerInterface::SetIncomingPassword ( const char * passwordData, int passwordDataLength )
virtual void ClearBanList (void)=0
Success conditions:
All functions pass tests.
Failure conditions:
Any function fails test.
Client connects with no password
Client connects with wrong password
Client failed to connect with correct password
Client was banned but connected anyways
GetIncomingPassword returned wrong password
IsBanned does not show localhost as banned
Localhost was not unbanned
Client failed to connect after banlist removal
Client failed to connect after banlist removal with clear function
Client did not connect encrypted
Client connected encrypted but shouldn't have
IsInSecurityExceptionList does not register localhost addition
RakPeerInterface Functions used, tested indirectly by its use:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
IsConnected
GetStatistics
RakPeerInterface Functions Explicitly Tested:
SetIncomingPassword
GetIncomingPassword
AddToBanList
IsBanned
RemoveFromBanList
ClearBanList
InitializeSecurity //Disabled because of RakNetStatistics changes
AddToSecurityExceptionList //Disabled because of RakNetStatistics changes
IsInSecurityExceptionList //Disabled because of RakNetStatistics changes
RemoveFromSecurityExceptionList //Disabled because of RakNetStatistics changes
*/
int SecurityFunctionsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
char thePassword[]="password";
server=RakPeerInterface::GetInstance();
client=RakPeerInterface::GetInstance();
client->Startup(1,&SocketDescriptor(),1);
server->Startup(1,&SocketDescriptor(60000,0),1);
server->SetMaximumIncomingConnections(1);
server->SetIncomingPassword(thePassword,(int)strlen(thePassword));
char returnedPass[22];
int returnedLen=22;
server->GetIncomingPassword(returnedPass,&returnedLen);
returnedPass[returnedLen]=0;//Password is a data block convert to null terminated string to make the test easier
if (strcmp(returnedPass,thePassword)!=0)
{
if (isVerbose)
{
printf("%s was returned but %s is the password\n",returnedPass,thePassword);
DebugTools::ShowError("GetIncomingPassword returned wrong password\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 5;
}
SystemAddress serverAddress;
serverAddress.SetBinaryAddress("127.0.0.1");
serverAddress.port=60000;
TimeMS entryTime=GetTimeMS();
if (isVerbose)
printf("Testing if no password is rejected\n");
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,0,0);
//.........这里部分代码省略.........
示例7: HandleUserLogin
//.........这里部分代码省略.........
}
else{
//password incorrect
info.loginTries++;
if (info.loginTries > 2){
info.locked = true;
info.loginTries = 3;
Logger::log("USER", "LOGIN", "User is LOCKED");
currentLoginStatus = UserSuccess::LOCKED;
}else{
Logger::log("USER", "LOGIN", "User has INCORRECT_PASSWORD");
currentLoginStatus = UserSuccess::INVALID_PASS;
}
}
AccountsTable::setAccessInfo(accountid, info);
}
}
//respond to the client
LoginStatusPacket loginStatusPacket;
// Set the loginStatus
loginStatusPacket.loginStatus = currentLoginStatus;
// Set Talk_Like_A_Pirate_String
loginStatusPacket.talkLikeAPirate = "Talk_Like_A_Pirate";
loginStatusPacket.unknownString = "";
// Set client version
loginStatusPacket.clientVersion1 = 1;
loginStatusPacket.clientVersion2 = 10;
loginStatusPacket.clientVersion3 = 64;
// This is unknown data...
loginStatusPacket.unknown = "_";
time_t t = time(NULL);
unsigned int addr = packet->systemAddress.binaryAddress;
long long a = (long long)t * (long long)addr;
std::string keyhash = md5(std::to_string(a));
std::wstring key = StringToWString(keyhash, 33);
// Get the user key
loginStatusPacket.userKey = key;
//loginStatusPacket.userKey = "0 9 4 e 7 0 1 a c 3 b 5 5 2 0 b 4 7 8 9 5 b 3 1 8 5 7 b f 1 c 3 ";
// Set chat IPs/Port and the other IP
loginStatusPacket.chatIp = "192.168.0.20"; //TODO: make dynamic
loginStatusPacket.chatPort = 2003;
loginStatusPacket.anotherIp = "192.168.0.20";
loginStatusPacket.possibleGuid = "00000000-0000-0000-0000-000000000000";
loginStatusPacket.zeroLong = 0;
// Set localization
loginStatusPacket.localizationChar[0] = 0x55;
loginStatusPacket.localizationChar[1] = 0x53;
loginStatusPacket.localizationChar[2] = 0x00;
// Subscribed?
loginStatusPacket.firstLoginSubscription = 1;
loginStatusPacket.subscribed = 0;
loginStatusPacket.zeroLongLong = 0;
loginStatusPacket.redirectIp = cfg->redirectIp;
loginStatusPacket.redirectPort = cfg->redirectPort;
// Set the error msg and the error msg length
// This message only shows
loginStatusPacket.errorMsg = "";
loginStatusPacket.errorMsgLength = loginStatusPacket.errorMsg.length();
std::string world_server_address;
SystemAddress serverAddr;
serverAddr.SetBinaryAddress(cfg->redirectIp);
serverAddr.port = cfg->redirectPort;
int instanceid = InstancesTable::getInstanceId(serverAddr);
if (instanceid == -1){
loginStatusPacket.loginStatus = UserSuccess::UNKNOWN2;
loginStatusPacket.errorMsg = "Universe not available";
currentLoginStatus = UserSuccess::UNKNOWN2;
Logger::log("AUTH", "LOGIN", "INSTANCE UNAVAILABLE", LOG_ERROR);
}
if (currentLoginStatus == UserSuccess::SUCCESS){
// Login the user to the server
Session::login(packet->systemAddress, accountid, keyhash, instanceid);
Logger::log("AUTH", "LOGIN", usernameA + " Logged-in");
SendStatusPacket(rakServer, packet->systemAddress, loginStatusPacket);
return;
}
SendStatusPacket(rakServer, packet->systemAddress, loginStatusPacket);
}
Logger::log("AUTH", "LOGIN", "Login failed", LOG_WARNING);
}
示例8: RunTest
//.........这里部分代码省略.........
{
if (isVerbose&&!printedYet)
{
printf("Client:\n");
printedYet=true;
}
if (p->data[0]==ID_NEW_INCOMING_CONNECTION)
{
if (isVerbose)
printf("ID_NEW_INCOMING_CONNECTION\n");
gotNotification=true;
}
else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
{
if (isVerbose)
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
gotNotification=true;
}
else if (p->data[0]==ID_UNCONNECTED_PING)
{
if (isVerbose)
printf("ID_PING\n");
connectionAttemptTime=GetTimeMS()+1000;
p->systemAddress.ToString(false,clientIP);
clientPort=p->systemAddress.port;
gotNotification=false;
}
else if (p->data[0]==ID_UNCONNECTED_PONG)
{
if (isVerbose)
printf("ID_UNCONNECTED_PONG\n");
TimeMS sendPingTime;
BitStream bs(p->data,p->length,false);
bs.IgnoreBytes(1);
bs.Read(sendPingTime);
TimeMS rtt = GetTimeMS() - sendPingTime;
if (rtt/2<=500)
connectionAttemptTime=GetTimeMS()+1000-rtt/2;
else
connectionAttemptTime=GetTimeMS();
gotNotification=false;
}
}
if (connectionAttemptTime!=0 && GetTimeMS()>=connectionAttemptTime)
{
if (isVerbose)
printf("Attemping connection\n");
connectionAttemptTime=0;
server->Connect(clientIP,clientPort,0,0);
client->Connect(serverIP,SERVER_PORT,0,0);
connectionResultDeterminationTime=GetTimeMS()+2000;
}
if (connectionResultDeterminationTime!=0 && GetTimeMS()>=connectionResultDeterminationTime)
{
connectionResultDeterminationTime=0;
if (gotNotification==false)
{
DebugTools::ShowError("Did not recieve expected response. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
SystemAddress sa;
sa.SetBinaryAddress(serverIP);
sa.port=SERVER_PORT;
client->CancelConnectionAttempt(sa);
sa.SetBinaryAddress(clientIP);
sa.port=clientPort;
server->CancelConnectionAttempt(sa);
server->CloseConnection(server->GetSystemAddressFromIndex(0),true,0);
client->CloseConnection(client->GetSystemAddressFromIndex(0),true,0);
//if (isServer==false)
nextTestStartTime=GetTimeMS()+1000;
}
if (nextTestStartTime!=0 && GetTimeMS()>=nextTestStartTime)
{
client->Ping(serverIP,SERVER_PORT,false);
nextTestStartTime=0;
}
RakSleep(0);
}
if (isVerbose)
printf("Test succeeded.\n");
return 0;
}
示例9: RunTest
//.........这里部分代码省略.........
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
printf("Entering disconnect loop \n");
bool printedYet;
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
//Disconnect all peers IF connected to any
for (int i=0;i<peerNum;i++)
{
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
for (int j=0;j<len;j++)//Disconnect them all
{
peerList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
}
}
RakSleep(100);
//Clear pending if not finished
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
peerList[i]->CancelConnectionAttempt(currentSystem); //Make sure a connection is not pending before trying to connect.
}
}
RakSleep(100);
//Connect
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if(CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,false,true,true))//Did we drop the pending connection?
{
if (isVerbose)
DebugTools::ShowError("Did not cancel the pending request \n",!noPauses && isVerbose,__LINE__,__FILE__);
示例10: RunTest
//.........这里部分代码省略.........
TimeMS entryTime=GetTimeMS();//Loop entry time
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
if (isVerbose)
printf("Entering disconnect loop \n");
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
//Disconnect all clients IF connected to any from client side
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
for (int j=0;j<len;j++)//Disconnect them all
{
clientList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
}
}
//RakSleep(100);
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
//Server receive
packet=server->Receive();
if (isVerbose&&packet)
printf("For server\n");
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
示例11: RunTest
int ComprehensiveConvertTest::RunTest(DataStructures::List<RakNet::RakString> params,bool isVerbose,bool noPauses)
{
static const int CONNECTIONS_PER_SYSTEM =4;
SystemAddress currentSystem;
// DebugTools::ShowError("Note: The conversion of this is on hold until the original sample's problem is known.",!noPauses && isVerbose,__LINE__,__FILE__);
// return 55;
// AutoRPC autoRpcs[NUM_PEERS];
//AutoRPC autoRpcs[NUM_PEERS];
int peerIndex;
float nextAction;
int i;
int portAdd;
char data[8096];
int seed = 12345;
if (isVerbose)
printf("Using seed %i\n", seed);
seedMT(seed);
for (i=0; i < NUM_PEERS; i++)
{
//autoRpcs[i].RegisterFunction("RPC1", RPC1, false);
//autoRpcs[i].RegisterFunction("RPC2", RPC2, false);
//autoRpcs[i].RegisterFunction("RPC3", RPC3, false);
//autoRpcs[i].RegisterFunction("RPC4", RPC4, false);
peers[i]=RakNetworkFactory::GetRakPeerInterface();
peers[i]->SetMaximumIncomingConnections(CONNECTIONS_PER_SYSTEM);
SocketDescriptor socketDescriptor(60000+i, 0);
peers[i]->Startup(NUM_PEERS, 0, &socketDescriptor, 1);
peers[i]->SetOfflinePingResponse("Offline Ping Data", (int)strlen("Offline Ping Data")+1);
peers[i]->ApplyNetworkSimulator(500,50,50);
// peers[i]->AttachPlugin(&autoRpc[i]);
}
for (i=0; i < NUM_PEERS; i++)
{
portAdd=randomMT()%NUM_PEERS;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+portAdd;
if(!peers[i]->IsConnected (currentSystem,true,true) )//Are we connected or is there a pending operation ?
{
if (!peers[i]->Connect("127.0.0.1", 60000+portAdd, 0, 0))
{
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
}
RakNetTime endTime = RakNet::GetTime()+10000;
while (RakNet::GetTime()<endTime)
{
nextAction = frandomMT();
if (nextAction < .04f)
{
// Initialize
peerIndex=randomMT()%NUM_PEERS;
SocketDescriptor socketDescriptor(60000+peerIndex, 0);
peers[peerIndex]->Startup(NUM_PEERS, randomMT()%30, &socketDescriptor, 1);
portAdd=randomMT()%NUM_PEERS;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+portAdd;
if(!peers[peerIndex]->IsConnected (currentSystem,true,true) )//Are we connected or is there a pending operation ?
{
if(!peers[peerIndex]->Connect("127.0.0.1", 60000+portAdd, 0, 0))
{
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
//.........这里部分代码省略.........
示例12: RunTest
//.........这里部分代码省略.........
if (isVerbose)
printf("Entering disconnect loop \n");
while(RakNet::GetTime()-entryTime<30000)//Run for 30 Secoonds
{
//Deallocate client IF connected
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if(len>=1)
{
RakNetworkFactory::DestroyRakPeerInterface(clientList[i]);
clientList[i]=RakNetworkFactory::GetRakPeerInterface();
SocketDescriptor tmp;
clientList[i]->Startup(1,30,&tmp, 1);
}
}
RakSleep(2000);//Allow connections to timeout.
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!clientList[i]->IsConnected (currentSystem,true,true) )//Are we connected or is there a pending operation ?
{
if (!clientList[i]->Connect("127.0.0.1", 60000, 0,0))
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
printf("Connecting clients\n");
RakSleep(2000);//Allow connections to timeout.
//Connect
for (int i=0;i<clientNum;i++)
{
示例13: main
int main(void)
{
PortAudioStream *stream;
PaError err;
mute=false;
bool quit;
char ch;
printf("A sample on how to use RakVoice. You need a microphone for this sample.\n");
printf("RakVoice relies on Speex for voice encoding and decoding.\n");
printf("See DependentExtensions/RakVoice/speex-1.1.12 for speex projects.\n");
printf("For windows, I had to define HAVE_CONFIG_H, include win32/config.h,\n");
printf("and include the files under libspeex, except those that start with test.\n");
printf("PortAudio is also included and is used to read and write audio data. You\n");
printf("can substitute whatever you want if you do not want to use portaudio.\n");
printf("Difficulty: Advanced\n\n");
// Since voice is peer to peer, we give the option to use the nat punchthrough client if desired.
NatPunchthroughClient natPunchthroughClient;
char port[256];
rakPeer = RakNetworkFactory::GetRakPeerInterface();
printf("Enter local port (enter for default): ");
gets(port);
if (port[0]==0)
strcpy(port, "60000");
SocketDescriptor socketDescriptor(atoi(port),0);
rakPeer->Startup(4, 30, &socketDescriptor, 1);
rakPeer->SetMaximumIncomingConnections(4);
rakPeer->AttachPlugin(&rakVoice);
rakPeer->AttachPlugin(&natPunchthroughClient);
rakVoice.Init(SAMPLE_RATE, FRAMES_PER_BUFFER*sizeof(SAMPLE));
err = Pa_Initialize();
if( err != paNoError ) goto error;
err = Pa_OpenStream(
&stream,
Pa_GetDefaultInputDeviceID(),
1, // Num channels, whatever that means
PA_SAMPLE_TYPE,
NULL,
Pa_GetDefaultOutputDeviceID(),
1, // Num channels
PA_SAMPLE_TYPE,
NULL,
SAMPLE_RATE,
FRAMES_PER_BUFFER, /* frames per buffer */
0, /* number of buffers, if zero then use default minimum */
0, /* paDitherOff, // flags */
PACallback,
0 );
if( err != paNoError ) goto error;
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
printf("Support NAT punchthrough? (y/n)? ");
bool useNatPunchthrough;
useNatPunchthrough=(getche()=='y');
printf("\n");
char facilitatorIP[256];
{//Linux fix. Won't compile without it. Because of the goto error above, the scope is ambigious. Make it a block to define that it will not be used after the jump.
//Doesn't change current logic
SystemAddress facilitator;
if (useNatPunchthrough)
{
printf("My GUID is %s\n", rakPeer->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString());
printf("Enter IP of facilitator (enter for default): ");
gets(facilitatorIP);
if (facilitatorIP[0]==0)
strcpy(facilitatorIP, "94.198.81.195");
facilitator.SetBinaryAddress(facilitatorIP);
facilitator.port=NAT_PUNCHTHROUGH_FACILITATOR_PORT;
rakPeer->Connect(facilitatorIP, NAT_PUNCHTHROUGH_FACILITATOR_PORT, 0, 0);
printf("Connecting to facilitator...\n");
}
else
{
printf("Not supporting NAT punchthrough.\n");
}
Packet *p;
quit=false;
if (useNatPunchthrough==false)
printf("(Q)uit. (C)onnect. (D)isconnect. C(l)ose voice channels. (M)ute. ' ' for stats.\n");
while (!quit)
{
if (kbhit())
{
ch=getch();
if (ch=='y')
{
quit=true;
}
//.........这里部分代码省略.........
示例14: main
//.........这里部分代码省略.........
if (sysIndex>=0 && sysIndex<NUM_PEERS)
{
rakPeer[sysIndex]->Shutdown(100,0);
SocketDescriptor socketDescriptor(60000+sysIndex,0);
rakPeer[sysIndex]->Startup(NUM_PEERS, 0, &socketDescriptor, 1);
printf("Restarting system %i.\n", sysIndex);
}
else
{
printf("Invalid range\n");
}
}
if (ch=='f' || ch=='F')
{
ch=0;
printf("Which system? 0 to %i\n", NUM_PEERS-1);
gets(str);
int sysIndex = atoi(str);
if (sysIndex>=0 && sysIndex<NUM_PEERS)
{
if (readyEventPlugin[sysIndex].ForceCompletion(0))
printf("Set system %i to force complete\n", sysIndex);
else
printf("Set system %i to force complete FAILED\n", sysIndex);
}
else
{
printf("Invalid range\n");
}
}
if (ch==' ')
{
SystemAddress sysAddr;
sysAddr.SetBinaryAddress("127.0.0.1");
unsigned j;
printf("\n");
PrintConnections();
for (i=0; i < NUM_PEERS; i++)
{
printf("System %i, ", i);
if (readyEventPlugin[i].IsEventSet(0))
printf("Set=True, ");
else
printf("Set=False, ");
if (readyEventPlugin[i].IsEventCompleted(0))
printf("Completed=True\n");
else if (readyEventPlugin[i].IsEventCompletionProcessing(0))
printf("Completed=InProgress\n");
else
printf("Completed=False\n");
for (j=0; j < NUM_PEERS; j++)
{
if (i!=j)
{
ReadyEventSystemStatus ress;
sysAddr.port=60000+j;
ress = readyEventPlugin[i].GetReadyStatus(0, sysAddr);
printf(" Remote system %i, status = ", j);
switch (ress)
{
case RES_NOT_WAITING:
printf("RES_NOT_WAITING\n");
示例15: RunTest
int PingTestsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *sender,*sender2, *receiver;
destroyList.Clear(false,_FILE_AND_LINE_);
TestHelpers::StandardClientPrep(sender,destroyList);
TestHelpers::StandardClientPrep(sender2,destroyList);
receiver=RakPeerInterface::GetInstance();
destroyList.Push(receiver,_FILE_AND_LINE_);
receiver->Startup(2, &SocketDescriptor(60000,0), 1);
receiver->SetMaximumIncomingConnections(2);
Packet * packet;
SystemAddress currentSystem;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
printf("Connecting sender2\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(sender2,receiver,5000))
{
if (isVerbose)
DebugTools::ShowError("Could not connect after 5 seconds\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
printf("Getting ping data for lastping and lowestping\n");
sender2->SetOccasionalPing(false);//Test the lowest ping and such without occassionalping,occasional ping comes later
RakTimer timer(1500);
int lastPing=0;
int lowestPing=0;
TimeMS nextPing=0;
while(!timer.IsExpired())
{
for (packet=receiver->Receive();packet;receiver->DeallocatePacket(packet),packet=receiver->Receive())
{
if (isVerbose)
printf("Receive packet id %i\n",packet->data[0]);
}
for (packet=sender2->Receive();packet;sender2->DeallocatePacket(packet),packet=sender2->Receive())
{
if (isVerbose)
printf("Send packet id %i\n",packet->data[0]);
}
if (GetTimeMS()>nextPing)
{
sender2->Ping(currentSystem);
nextPing=GetTimeMS()+30;
}
RakSleep(3);
}
int averagePing=sender2->GetAveragePing(currentSystem);
if (isVerbose)
printf("Average Ping time %i\n",averagePing);
lastPing=sender2->GetLastPing(currentSystem);
lowestPing=sender2->GetLowestPing(currentSystem);
if (isVerbose)
printf("Last Ping time %i\n",lastPing);
if (isVerbose)
printf("Lowest Ping time %i\n",lowestPing);
int returnVal=TestAverageValue(averagePing,__LINE__, noPauses, isVerbose);
if (returnVal!=0)
{
return returnVal;
}
if (lastPing>100)//100 MS for localhost?
{
if (isVerbose)
DebugTools::ShowError("Problem with the last ping time,greater then 100MS for localhost\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
if (lowestPing>10)//The lowest ping for localhost should drop below 10MS at least once
{
if (isVerbose)
DebugTools::ShowError("The lowest ping for localhost should drop below 10MS at least once\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
//.........这里部分代码省略.........