Adafruit_CC3000_Library/Adafruit_CC3000_Server.cpp
// Initialize the server and start listening for connections.
Initialize the server and start listening for connections.
Initialize the server and start listening for connections .
void Adafruit_CC3000_Server::begin() {
  unsigned long aucDHCP       = 14400;
  unsigned long aucARP        = 3600;
  unsigned long aucKeepalive  = 30;
  unsigned long aucInactivity = 0;
  cc3k_int_poll();
  if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) {
    CC3K_PRINTLN_F("Error setting inactivity timeout!");
    return;
  }
  cc3k_int_poll();
  int16_t soc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (soc < 0) {
    CC3K_PRINTLN_F("Couldn't create listening socket!");
    return;
  }
  cc3k_int_poll();
  char arg = SOCK_ON; 
  if (setsockopt(soc, SOL_SOCKET, SOCKOPT_ACCEPT_NONBLOCK, &arg, sizeof(arg)) < 0) {
    CC3K_PRINTLN_F("Couldn't set socket as non-blocking!");
    return;
  }
  sockaddr_in address;
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = htonl(0);     
  address.sin_port = htons(_port);        
  cc3k_int_poll();
  if (bind(soc, (sockaddr*) &address, sizeof(address)) < 0) {
    CC3K_PRINTLN_F("Error binding listen socket to address!");
    return;
  }
  cc3k_int_poll();
  if (listen(soc, 0) < 0) {
    CC3K_PRINTLN_F("Error opening socket for listening!");
    return;
  }
  _listenSocket = soc;
}
void Adafruit_CC3000_Server :: begin ( ) { unsigned long aucDHCP = 14400 ; unsigned long aucARP = 3600 ; unsigned long aucKeepalive = 30 ; unsigned long aucInactivity = 0 ; cc3k_int_poll ( ) ; if ( netapp_timeout_values ( & aucDHCP , & aucARP , & aucKeepalive , & aucInactivity ) != 0 ) { CC3K_PRINTLN_F ( " " ) ; return ; } cc3k_int_poll ( ) ; int16_t soc = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ) ; if ( soc < 0 ) { CC3K_PRINTLN_F ( " " ) ; return ; } cc3k_int_poll ( ) ; char arg = SOCK_ON ; if ( setsockopt ( soc , SOL_SOCKET , SOCKOPT_ACCEPT_NONBLOCK , & arg , sizeof ( arg ) ) < 0 ) { CC3K_PRINTLN_F ( " " ) ; return ; } sockaddr_in address ; address . sin_family = AF_INET ; address . sin_addr . s_addr = htonl ( 0 ) ; address . sin_port = htons ( _port ) ; cc3k_int_poll ( ) ; if ( bind ( soc , ( sockaddr * ) & address , sizeof ( address ) ) < 0 ) { CC3K_PRINTLN_F ( " " ) ; return ; } cc3k_int_poll ( ) ; if ( listen ( soc , 0 ) < 0 ) { CC3K_PRINTLN_F ( " " ) ; return ; } _listenSocket = soc ; }
Initialize the server and start listening for connections.
Initialize the server and start listening for connections .
// Set the CC3000 inactivity timeout to 0 (never timeout).  This will ensure  // the CC3000 does not close the listening socket when it's idle for more than  // 60 seconds (the default timeout).  See more information from: // http://e2e.ti.com/support/low_power_rf/f/851/t/292664.aspx // Create a TCP socket // Set the socket's accept call as non-blocking. // nsd: looked in TI example code and they pass this as a 'short' in one example, and 'char' in two others. 'char' seems as likely work, and has no endianess issue // Bind the socket to a TCP address. // Listen on any network interface, equivalent to INADDR_ANY in sockets programming. // Listen on the specified port. // Start listening for connections. // The backlog parameter is 0 as it is not supported on TI's CC3000 firmware.