本文整理汇总了C++中UdpSocket::ackTo方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpSocket::ackTo方法的具体用法?C++ UdpSocket::ackTo怎么用?C++ UdpSocket::ackTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpSocket
的用法示例。
在下文中一共展示了UdpSocket::ackTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serverReliable
void serverReliable( UdpSocket &sock, const int max, int message[] ) {
cerr << "server stop and wait:" << endl;
// receive message[] max times
int seq;
while(seq != max - 1) {
while( sock.pollRecvFrom() <=0 ){} // pause until message
sock.recvFrom( ( char * ) message, MSGSIZE ); // udp message receive
seq = *message; // get the seq # from beginning of msg
sock.ackTo((char*)&seq, sizeof(seq));
}
}
示例2: serverEarlyRetrans
void serverEarlyRetrans(UdpSocket &sock, const int max, int message[],
int windowSize, int loss) {
cerr << "Server early retrans test:" << endl;
int ack; // Holds the acknowledgment
bool serverArray[max]; // Holds messages that server needs from client
int sequence = 0; // The sequence # counter
// Init values in serverArray
for (int i = 0; i < max; i++)
serverArray[i] = false;
while (sequence < max) {
// Read the message from the client
sock.recvFrom((char *)message, MSGSIZE);
// Drop packets randomly
if (rand() % 100 < loss) {
continue;
}
// Got needed message from client
if (message[0] == sequence) {
// Set the serverArray at sequence
serverArray[sequence] = true;
// Find the lowest number the server needs
while (sequence < max) {
if (serverArray[sequence] == false) {
break;
}
sequence++;
}
// Send an ACK for previous seq #
ack = sequence - 1;
}
else {
// Set the serverArray at message
serverArray[message[0]] = true;
// Send the number that is still needed
ack = sequence;
}
// Send the acknowledgment
sock.ackTo((char *)&ack, sizeof(ack));
}
}
示例3: serverReliable
void serverReliable( UdpSocket &sock, const int max, int message[] ) {
cerr << "server reliable test:" << endl;
// receive message[] max times
for ( int i = 0; i < max; ) {
sock.recvFrom( ( char * ) message, MSGSIZE ); // udp message receive
if ( message[0] >= max ) {
cerr << "ERROR: " << message[0] << " is larger than max\n";
break;
}
// Drops the message[] if its a duplicate
if ( message[0] == i ) {
sock.ackTo( ( char * ) message, MSGSIZE); // send ACK to client
//cerr << " ACKed: " << message[0] << endl;
i++;
}
}
}
示例4: ackPkt
int ackPkt(int n, UdpSocket &sock) {
return sock.ackTo((char*)&n, sizeof(int));
}