1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/*
* Modification History
*
* 2002-April-12 Jason Rohrer
* Created.
*/
#include "minorGems/network/Socket.h"
#include "minorGems/network/SocketServer.h"
#include <stdlib.h>
void usage( char *inAppName );
int main( int inNumArgs, char **inArgs ) {
if( inNumArgs != 2 ) {
usage( inArgs[0] );
}
int port;
int numRead = sscanf( inArgs[1], "%d", &port );
if( numRead != 1 ) {
usage( inArgs[0] );
}
SocketServer *server = new SocketServer( port, 100 );
char timedOut;
Socket *sock;
printf( "waiting for connection on port %d\n", port );
sock = server->acceptConnection( 5000, &timedOut );
if( timedOut ) {
printf( "timed out after 5 seconds, waiting again\n" );
sock = server->acceptConnection( 5000, &timedOut );
}
if( !timedOut && sock != NULL ) {
printf( "connection received\n" );
delete sock;
}
else {
printf( "timed out again\n" );
}
delete server;
return 1;
}
void usage( char *inAppName ) {
printf( "Usage:\n" );
printf( " %s port_number\n", inAppName );
exit( 1 );
}
|