Example #1
0
void OpenClient( void )
{
	PSOCKADDR pAddr;
	if( l.flags.bUDP )
	{
		pAddr = CreateSockAddress( WIDE("127.0.0.1:10005"), 10005 );
      l.pClient = ConnectUDPAddr( pAddr, l.pAddr, UDPClientRead, NULL );
	}
	else
	{
		if( l.flags.bUnix )
			pAddr = CreateRemote( WIDE("./TestSocket"), 0 );
		else
			pAddr = CreateSockAddress( WIDE("127.0.0.1:10000"), 10000 );
		l.pClient = OpenTCPClientAddrEx( pAddr, ClientReadComplete, NULL, NULL );
      SetTCPNoDelay( l.pClient, 1 );
	}
}
Example #2
0
void OpenServer( void )
{
	PCLIENT pServer;
	PSOCKADDR pAddr;
	if( l.flags.bUDP )
	{
		l.pAddr = CreateSockAddress( WIDE("127.0.0.1:10001"), 10001 );
      pServer = ServeUDPAddr( l.pAddr, UDPServerRead, NULL );
	}
	else
	{
		if( l.flags.bUnix )
			pAddr = CreateRemote( WIDE("./TestSocket"), 0 );
		else
			pAddr = CreateSockAddress( WIDE("127.0.0.1:10000"), 10000 );
		pServer = OpenTCPListenerAddrEx( pAddr, Connected );
      SetTCPNoDelay( pServer, 1 );
	}
}
Example #3
0
int main( int argc, char** argv )
{
	SOCKADDR *sa;
   int n;
	if( argc < 2 )
	{
		printf( "usage: %s <Telnet IP[:port]>\n", argv[0] );
		return 0;
	}
	SystemLog( "Starting the network" );
	NetworkStart();
	SystemLog( "Started the network" );
   sa = CreateSockAddress( argv[1], 23 );
	//if( argc >= 3 ) port = atoi( argv[2] ); else port = 23;
	pc_user = OpenTCPClientAddrExx( sa, ReadComplete, Closed, NULL, Connected );

	if( !pc_user )
	{
		SystemLog( "Failed to open some port as telnet" );
		printf( "failed to open %s%s\n", argv[1], strchr(argv[1],':')?"":":telnet[23]" );
		return 0;
	}
	for( n = 0; n < 1000; n++ )
	{
		if( (rand() & 3) != 0 )
		{
         WakeableSleep( rand() %1000 );
		}
      lprintf( "..." );
		RemoveClient( pc_user );
		pc_user = OpenTCPClientAddrExx( sa, ReadComplete, Closed, NULL, Connected );
		lprintf( "..." );
		if( (rand() &3) < 3 )
		{
         fflush( stdout );
			while( !connected )
				Relinquish();
		}
		if( connected )
		{
         lprintf( "send." );
			SendTCP( pc_user, "test", 4 );
		}
	}
	return -1;
}