本文整理汇总了C++中NetConnection::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ NetConnection::Connect方法的具体用法?C++ NetConnection::Connect怎么用?C++ NetConnection::Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetConnection
的用法示例。
在下文中一共展示了NetConnection::Connect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
srand(NetGetTime());
Peer* sender; int size;
NetConnection connection;
connection.Open(5008);
NetConnection server;
server.Open(5007);
connection.connection.SetRTT(0);
connection.connection.SetDrop(0);
connection.connection.SetVariance(0);
printf("Doing Connection Security Test\n");
for (int i = 0; i < 50; i++)
{
char* buffer = new char[i*6];
for (int in = 0; in < i*6; in++)
{
buffer[in] = rand();
}
connection.connection.Send(Address(127,0,0,1,5007), buffer, i*6);
delete[] buffer;
}
NetSleep(1000);//wait to receive messages
//get all messages out
char* out;
while (out = server.Receive(sender, size))
{
delete[] out;
}
if (server.peers.size() != 0)
printf("Connection security test failed!!!\n\n");
else
printf("Connection security test passed.\n\n");
auto t = std::thread([](NetConnection* server)
{
while (true)
{
Peer* sender; int size;
server->Receive(sender, size);
if (server->peers.size() > 5)
return;
}
}, &server);
int status = connection.Connect(Address(127,0,0,1,5007), "testing", 0);
if (status < 0)
{
printf("Connection Test Failed!!!\n");
}
NetConnection cons[5];
for (int i = 0; i < 5; i ++)
{
cons[i].Open(5010+i);
int stat = cons[i].Connect(Address(127,0,0,1,5007), "yo", 0);
if (stat < 0)
printf("Connection test failed!\n");
}
if (t.joinable())
t.join();
printf("Connection Test Successful\n");
for (int i = 0; i < 5; i++)
{
//cons[i].Disconnect();
cons[i].Close();
}
while (server.peers.size() > 1)
{
Peer* s; int size;
server.Receive(s, size);
NetSleep(1);
}
printf("Connections closed successfully\n\n");
printf("Doing Security Test\n");
for (int i = 0; i < 50; i++)
{
char* buffer = new char[i*6];
for (int in = 0; in < i*6; in++)
{
buffer[in] = rand();
}
//.........这里部分代码省略.........