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


C++ Address::GetD方法代码示例

本文整理汇总了C++中Address::GetD方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::GetD方法的具体用法?C++ Address::GetD怎么用?C++ Address::GetD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Address的用法示例。


在下文中一共展示了Address::GetD方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_address

void test_address()
{
	printf( "-----------------------------------------------------\n" );
	printf( "test address\n" );
	printf( "-----------------------------------------------------\n" );
	
	printf( "defaults\n" );
	{
		Address address;
		check( address.GetA() == 0 );
		check( address.GetB() == 0 );
		check( address.GetC() == 0 );
		check( address.GetD() == 0 );
		check( address.GetPort() == 0 );
		check( address.GetAddress() == 0 );
	}
	
	printf( "a,b,c,d,port\n" );
	{
		const unsigned char a = 100;
		const unsigned char b = 110;
		const unsigned char c = 50;
		const unsigned char d = 12;
		const unsigned short port = 10000;
		Address address( a, b, c, d, port );
		check( a == address.GetA() );
		check( b == address.GetB() );
		check( c == address.GetC() );
		check( d == address.GetD() );
		check( port == address.GetPort() );
	}

	printf( "equality/inequality\n");
	{
		Address x(100,110,0,1,50000);	
		Address y(101,210,6,5,50002);
		check( x != y );
		check( y == y );
		check( x == x );
	}
}
开发者ID:bitfixer,项目名称:bitfixer,代码行数:41,代码来源:Test.cpp

示例2: main

int main( int argc, char * argv[] )
{
	// initialize socket layer

	if ( !InitializeSockets() )
	{
		printf( "failed to initialize sockets\n" );
		return 1;
	}
	
	// create socket

	int port = 30000;

	if ( argc == 2 )
		port = atoi( argv[1] );

	printf( "creating socket on port %d\n", port );

	Socket socket;
	if ( !socket.Open( port ) )
	{
		printf( "failed to create socket!\n" );
		return 1;
	}

	// read in addresses.txt to get the set of addresses we will send packets to

	vector<Address> addresses;

	string line;
	ifstream file( "addresses.txt" );
	if ( !file.is_open() )
	{
		printf( "failed to open 'addresses.txt'\n" );
		return 1;
	}

	while ( !file.eof() )
	{
		getline( file, line );
		int a,b,c,d,port;
		if ( sscanf( line.c_str(), "%d.%d.%d.%d:%d", &a, &b, &c, &d, &port ) == 5 )
			addresses.push_back( Address( a,b,c,d,port ) );
	}

	file.close();

	// send and receive packets until the user ctrl-breaks...

	while ( true )
	{
		const char data[] = "hello world!";
		for ( int i = 0; i < (int) addresses.size(); ++i )
			socket.Send( addresses[i], data, sizeof( data ) );
			
		while ( true )
		{
			Address sender;
			unsigned char buffer[256];
			int bytes_read = socket.Receive( sender, buffer, sizeof( buffer ) );
			if ( !bytes_read )
				break;
		
			printf( "received packet from %d.%d.%d.%d:%d (%d bytes)\n", sender.GetA(), sender.GetB(), sender.GetC(), sender.GetD(), sender.GetPort(), bytes_read );
		}
		
		wait_seconds( 1.0f );
	}
	
	// shutdown socket layer
	
	ShutdownSockets();

	return 0;
}
开发者ID:alexsharoff,项目名称:netgame-examples,代码行数:76,代码来源:Node.cpp


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