예제 #1
0
void OSCServer::firstContact(lo_address addr) {
    touchOSC = lo_address_new(lo_address_get_hostname(addr),"9000");
    sendTrackBank(trackBank);
    sendBusBank(busBank);
    sendMaster();
}
예제 #2
0
int main ( int argc, char * argv[ ] ) {
  int sock, nuSock;          // This will be our sockets
  int nbytes;                // Number of bytes we receive in our message
  int code;                  // Error code for Select
  char buffer[ MAXBUFSIZE ]; // A buffer to store our received message
  char msg[ MAXBUFSIZE ];    // A Message to return
  Repository repo;           // The registration list
  fd_set fds;
  struct timeval timeout;
  int count = 0;

  //
  // Make sure port is given on command line
  // 
  if ( argc != 2 ) {
	printf( "USAGE:  <port>\n" );
	exit( EXIT_FAILURE );
  }

  //
  // Initialize all the things!
  //
  repo.total = 0;
  maxPrint( &repo );
  sock = createSocket( atoi( argv[1] ) );

  timeout.tv_sec = 2;
  timeout.tv_usec = 0;

  FD_ZERO( &fds );
  FD_SET( sock, &fds );
  nuSock = acceptConnection( sock );
  ERROR( nuSock < 0 );
  FD_SET( nuSock, &fds );
  
  //
  // Enter command loop
  //
  for ( ; ; ) {
	/*	if ( ( code = select( sizeof( fds )*8, &fds, NULL, NULL, &timeout ) ) < 0 ) {
	  ERROR( code < 0 );
	}
	else if ( code == 0 ) {
	  printf( "$ Timeout [%i]\r", count = ++count % 100 );
	  ERROR( count );
	}
	else {
	  count = 0;
	  if ( FD_ISSET( sock, &fds ) ) {
		// Loop through all the conenctions Available
		while ( ( nuSock = acceptConnection( sock ) ) > 0 );
		FD_SET( nuSock, &fds );
	  }
	*/	  
	ERROR( nuSock < 0 );
	bzero( buffer, MAXBUFSIZE );
	nbytes = read( nuSock, buffer, MAXBUFSIZE );
	ERROR( nbytes < 0 );
	printf( "[%s] %s\n", repo.cxn[whoisthis( &repo, nuSock )].name, buffer );
	
	switch ( parseCmd ( buffer ) ) 
	  {
	  case CONNECT:
		{
		  nbytes = write( nuSock, buffer, MAXBUFSIZE );
		  ERROR( nbytes < 0 );
		  switch( registerClient( &repo, nuSock ) ) 
			{
			case SUCCESS:
			  getList ( &repo, nuSock );
			  printf( "> Success in registering '%s'\n", repo.cxn[repo.total-1].name );
			  break;
			case FAILURE:
			  printf( "> Error in registration\n" );
			  break;
			}
		  break;
		}
	  case GET:
		sendMaster( &repo, nuSock );
		break;
	  case EXIT:
		{
		  switch( removeClient( &repo, nuSock ) ) {
		  case SUCCESS: 
			printf( "> Client has been removed.\n" );
			break;
		  case FAILURE:
			printf( "> Error removing client.\n" );
			break;
		  }
		  break;
		}
	  default: 
		sprintf( msg, "Invalid command: '%s'", buffer); 
		nbytes = write( nuSock, msg, MAXBUFSIZE );
		ERROR( nbytes < 0 );
		break;
	  }
  }
  
  close( nuSock );
  close( sock );
  
  return EXIT_SUCCESS;
} // main( )