本文整理汇总了C++中Address::GetA方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::GetA方法的具体用法?C++ Address::GetA怎么用?C++ Address::GetA使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::GetA方法的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 );
}
}
示例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;
}