当前位置: 首页>>代码示例>>C++>>正文


C++ UdpSocket::ackTo方法代码示例

本文整理汇总了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));
	}
}
开发者ID:jahennen,项目名称:CSS_432,代码行数:12,代码来源:udp.cpp

示例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));
	}

}
开发者ID:blong43,项目名称:css432,代码行数:49,代码来源:udpa.cpp

示例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++;
		}
	}
}
开发者ID:blong43,项目名称:css432,代码行数:20,代码来源:udp.cpp

示例4: ackPkt

int ackPkt(int n, UdpSocket &sock) {
	return sock.ackTo((char*)&n, sizeof(int));
}
开发者ID:jahennen,项目名称:CSS_432,代码行数:3,代码来源:udp.cpp


注:本文中的UdpSocket::ackTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。