本文整理汇总了C++中TCPSocket::setupToReceive方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::setupToReceive方法的具体用法?C++ TCPSocket::setupToReceive怎么用?C++ TCPSocket::setupToReceive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::setupToReceive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
printf ("trying to connect to %s:%d...\n", (const char*) strNextNodeHost, iNextNodePort);
fflush (stdout);
if (0 != (rc = pSocketToNextNode->connect (strNextNodeHost, iNextNodePort))) {
printf ("failed - will try again in 2 seconds\n");
sleepForMilliseconds (2000);
}
else {
printf ("Connected\n");
break;
}
}
SocketWriter sw (pSocketToNextNode);
BufferedWriter bw (&sw, 2048);
// Freeze
int result;
uint64 ui64StartFreeze = getTimeInMilliseconds();
result = pMocket->getState (&bw);
printf ("TIME FOR GETSTATE ** %llu **\n", (getTimeInMilliseconds() - ui64StartFreeze));
printf ("getState ended with status %d\n", result);
if (0 != result) {
delete pMocket;
return -3;
}
}
else if (0 == stricmp (argv[1], "receiver")) {
// Create the Server Socket
int rc;
TCPSocket *pServerSocket;
pServerSocket = new TCPSocket();
int iLocalPortNum = 4444;
if (0 != (rc = pServerSocket->setupToReceive (iLocalPortNum))) {
return -3;
}
printf ("listening on port %d\n", iLocalPortNum);
Socket *pSocketFromPreviousNode;
// Wait for connection from previous node
printf ("Waiting for connection from previous node...\n");
fflush (stdout);
pSocketFromPreviousNode = pServerSocket->accept();
if (pSocketFromPreviousNode == NULL) {
printf ("Failed\n");
return -4;
}
printf ("Connected\n");
pSocketFromPreviousNode->bufferingMode(0);
SocketReader sr (pSocketFromPreviousNode);
BufferedReader br (&sr);
// Resume
int result;
uint64 ui64StartResumeAndRestoreState = getTimeInMilliseconds();
result = pMocket->resumeAndRestoreState (&br);
printf ("TIME FOR RESUMEANDRESTORESTATE ** %llu **\n", (getTimeInMilliseconds() - ui64StartResumeAndRestoreState));
printf ("resumeFromSuspension ended with status %d\n", result);
if (0 != result) {
printf ("ERROR\n");
delete pMocket;
return -5;
}