本文整理汇总了C++中HostAddress::print方法的典型用法代码示例。如果您正苦于以下问题:C++ HostAddress::print方法的具体用法?C++ HostAddress::print怎么用?C++ HostAddress::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HostAddress
的用法示例。
在下文中一共展示了HostAddress::print方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
char *name = new char[99];
sprintf( name, "63.249.65.249" );
//char *name = new char[99];
//sprintf( name, "192.168.1.2" );
//char *name = "192.168.1.1";
//int addressLength = 11;
//char *name = "monolith.2y.net";
//int addressLength = 15;
int port = 5158;
HostAddress *address = new HostAddress( name, port );
printf( "Trying to connect to server: " );
address->print();
printf( "\n" );
Socket *sock;
int numConnections = 0;
while( true ) {
sock = SocketClient::connectToServer( address );
if( sock == NULL ) {
printf( "%d Connecting to server failed\n", numConnections );
//return 1;
}
else {
printf( "%d Connection established\n", numConnections );
HostAddress *localAddress = sock->getLocalHostAddress();
if( localAddress != NULL ) {
printf( "Our local address (fetched from socket) is " );
localAddress->print();
printf( "\n" );
delete localAddress;
}
delete sock;
}
//usleep( 1000 );
numConnections++;
}
int numBytes = 4000;
unsigned char *buffer = new unsigned char[numBytes];
for( int i=0; i<numBytes; i++ ) {
buffer[i] = i;
}
SocketStream *stream = new SocketStream( sock );
//printf( "sleeping\n" );
//sleep( 10 );
int count = 0;
while( true ) {
printf( "sending %d bytes\n", numBytes );
int numSent = stream->write( buffer, numBytes );
printf( "Sent %d successfully,\tcount = %d\n", numSent, count );
count++;
}
int checksum = 0;
for( int i=0; i<numBytes; i++ ) {
checksum += buffer[ i ];
}
printf( "Checksum: %d\n", checksum );
printf( "Deleting stream\n" );
delete stream;
printf( "Deleting socket\n" );
delete sock;
printf( "Deleting address\n" );
delete address;
printf( "Returning\n" );
return 0;
}