int main(int argc, char *argv[])
{
	int sfd = startServer();   
   	serverLoop(sfd);
   	close(sfd);
   	return 0;
}
void WiFiManager::startWebConfig() {
    DEBUG_PRINT("");
    display.print("WiFi connected");
    DEBUG_PRINT("WiFi connected");
    DEBUG_PRINT(WiFi.localIP());
    DEBUG_PRINT(WiFi.softAPIP());
    if (!mdns.begin(_apName, WiFi.localIP())) {
        DEBUG_PRINT("Error setting up MDNS responder!");
        display.print("mDNS error");
        while(1) {
            delay(1000);
        }
    }
    DEBUG_PRINT("mDNS responder started");
    // Start the server
    server_s.begin();
    display.print("Server started");
    DEBUG_PRINT("Server started");

    while(serverLoop() == WM_WAIT) {
      //looping
    }

    display.print("All done.  Bye.");
    DEBUG_PRINT("Setup done");
    delay(10000);
    ESP.reset();
}
//-------------------------------------------------------------------------------------
void GalactiCombatServer::startServer(long portNo)
{
    if(verbose) std::cout << "Entering startServer" << std::endl;
    IPaddress ip; //32-bit IPv4 host, 16-bit port
    const char *host = NULL;
    Uint16 port = (Uint16)portNo;
    
    isServer = true;
    
    if(NetworkUtil::ResolveHost(&ip, NULL, port)==-1) exit(3);
    
    TCPServerSock = NetworkUtil::TCPOpen(&ip);
    if(!TCPServerSock) exit(4);

    /*
    UDPServerSock = NetworkUtil::UDPOpen(0);
    if(!UDPServerSock) exit(4);
    */

    //set up the game environment
    if(verbose) std::cout << "Setting up game...." << std::endl;
    mRoot = new Ogre::Root();
    chooseSceneManager();
    this->createServerMinerals();
    this->createServerRoom();
    
    host = SDLNet_ResolveIP(&ip);
    if(host == NULL)
        host = "N/A";
    if(verbose) std::cout << "Host: " << host << std::endl;
    
    if(verbose) std::cout << "Exiting startServer" << std::endl << std::endl;
    std::cout<<"Ready!"<<std::endl;
    serverLoop();
}
Beispiel #4
0
void WiFiManager::startWebConfig() {
  DEBUG_PRINT("");
  DEBUG_PRINT("WiFi connected");
  DEBUG_PRINT(WiFi.localIP());
  DEBUG_PRINT(WiFi.softAPIP());
  if (!mdns.begin(_apName, WiFi.localIP())) {
    DEBUG_PRINT("Error setting up MDNS responder!");
    while (1) {
      delay(1000);
    }
  }
  DEBUG_PRINT("mDNS responder started");
  // Start the server
  server.begin();
  DEBUG_PRINT("Server started");

  while (serverLoop() == WM_WAIT) {
    //looping
    if(timeout > 0 && start + timeout < millis()) {
      //we passed timeout value, release
      DEBUG_PRINT("timeout reached");
      return;
    }
  }

  DEBUG_PRINT("Setup done");
  delay(5000);
  ESP.reset();

}
Beispiel #5
0
int main(int argc, char* argv[]) {
	// setup signal handlers
	setHandler(SIGINT, signalHandler, 0);
	setHandler(SIGHUP, signalHandler, 1);

	//initialize port and counts
	serverPort = 2000;
	clientCount = 0;
	killCount = 0;

	// check arg count and scan in arg
	if (argc != 2){
		fprintf(stderr, "Error: Too few or too many arguments to %s.\n", argv[0]);
		cleanup();
		exit(0);
	}
	strncpy(configPath, argv[1], strlen(argv[1]));

	// open the log files
	serverlog = fopen(getenv("PROCNANNYSERVERINFO"), "w");
	logfile = fopen(getenv("PROCNANNYLOGS"), "w");

    readFile();										/* read in the config file */
    killPrevious("procnanny.server", getpid()); 	/* kill previous instances of procnanny server */

    // server loops forever until it is sent SIGINT
    serverLoop();

    /* shouldn't get here */
    return (EXIT_SUCCESS);
}
int main ()
{
   int sfd;

   printf("\n\nThe Client List is:");
   display_clist();
   make_table();
   sfd = startServer();
   serverLoop(sfd);
   return 0;
}
Beispiel #7
0
/**
 * Opens a connection, exchanges a session key and
 * communicates with symmetric encryption using the
 * session key
 */
int main(int argc , char *argv[]){

    /* Wait for a connection */
    int client_sock = openConnection();

    /* exchange encryption keys */
    unsigned char *session_key = getSessionKey(client_sock);

    /* client-server communication */
    serverLoop(client_sock, session_key);
    
    return 0;
}
Beispiel #8
0
void runServer(const McrouterStandaloneOptions& standaloneOpts,
               mcrouter_t& router) {
  AsyncMcServer::Options opts;

  if (standaloneOpts.listen_sock_fd >= 0) {
    opts.existingSocketFd = standaloneOpts.listen_sock_fd;
  } else {
    opts.ports = standaloneOpts.ports;
    opts.sslPorts = standaloneOpts.ssl_ports;
    opts.pemCertPath = router.opts.pem_cert_path;
    opts.pemKeyPath = router.opts.pem_key_path;
    opts.pemCaPath = router.opts.pem_ca_path;
  }

  opts.numThreads = router.opts.num_proxies;

  opts.worker.versionString = MCROUTER_PACKAGE_STRING;
  opts.worker.maxInFlight = standaloneOpts.max_client_outstanding_reqs;
  opts.worker.sendTimeout = std::chrono::milliseconds{
    router.opts.server_timeout_ms};

  /* Default to one read per event to help latency-sensitive workloads.
     We can make this an option if this needs to be adjusted. */
  opts.worker.maxReadsPerEvent = 1;
  opts.worker.requestsPerRead = standaloneOpts.requests_per_read;

  try {
    LOG(INFO) << "Spawning AsyncMcServer";

    AsyncMcServer server(opts);
    server.spawn(
      [&router] (size_t threadId,
                 folly::EventBase& evb,
                 AsyncMcServerWorker& worker) {
        serverLoop(router, threadId, evb, worker);
      }
    );

    server.installShutdownHandler({SIGINT, SIGTERM});
    server.join();

    LOG(INFO) << "Shutting down";
  } catch (const std::exception& e) {
    LOG(ERROR) << e.what();
  }
}
int main(int argc, const char * argv[])
{
    io_iterator_t	serialPortIterator;
    char            bsdPath[MAXPATHLEN];
    
    if(udpServerInit() != 0) {
        consoleNotef("Simulator link input port open failed.\n");
        return -1;
    }

    if(initConsoleInput() != 0) {
        consoleNotef("Console input initialization failed.\n");
        return -2;
    }
    
    Boolean looking = false;

    while(1) {
        if(!looking) {
            consoleNotef("Looking for the serial port...\n");
            looking = true;
        }
        
        if(findModems(&serialPortIterator) == KERN_SUCCESS) {
            if(getModemPath(serialPortIterator, bsdPath, sizeof(bsdPath)) == KERN_SUCCESS) {
                if(openSerialPort(bsdPath) != -1) {
                    serverInit();
                    
                    consoleNotef("Entering server loop...\n");
                    serverLoop();
                    consoleNotef("Server loop exited.\n");
             
                    closeSerialPort(serialPort);
                    looking = false;
                } else
                    consoleNotef("Serial port could not be opened.\n");
            }
            
            IOObjectRelease(serialPortIterator);
        }

        sleep(1);
    }

    return EX_OK;
}
Beispiel #10
0
int main(int argc, char *argv[])
{
    parseCommandLine(argc, argv);
    logInit("certserv", arg.useSyslog, arg.verbose, arg.logMask);
    //logNorm("arg.verbose = %d, arg.log_mask = %d\n", arg.verbose, arg.logMask);
    //logNorm("arg.chunks = %s\n", arg.chunks);

    if (init() < 0)
        dieError("init()\n");

	// Skip the slash
	if (arg.url[0] == '/')
		arg.url++;
    logVerb("host = '%s', url = '%s', port = %d\n", arg.host, arg.url, arg.port);

    if (arg.isServer)
        serverLoop();
    else
        client();

    return 0;
}
Beispiel #11
0
bool runServer(const McrouterStandaloneOptions& standaloneOpts,
               const McrouterOptions& mcrouterOpts) {
  AsyncMcServer::Options opts;

  if (standaloneOpts.listen_sock_fd >= 0) {
    opts.existingSocketFd = standaloneOpts.listen_sock_fd;
  } else if (!standaloneOpts.unix_domain_sock.empty()) {
    opts.unixDomainSockPath = standaloneOpts.unix_domain_sock;
  } else {
    opts.ports = standaloneOpts.ports;
    opts.sslPorts = standaloneOpts.ssl_ports;
    opts.pemCertPath = mcrouterOpts.pem_cert_path;
    opts.pemKeyPath = mcrouterOpts.pem_key_path;
    opts.pemCaPath = mcrouterOpts.pem_ca_path;
  }

  opts.numThreads = mcrouterOpts.num_proxies;

  opts.setPerThreadMaxConns(standaloneOpts.max_conns, opts.numThreads);
  opts.tcpListenBacklog = standaloneOpts.tcp_listen_backlog;
  opts.worker.defaultVersionHandler = false;
  opts.worker.maxInFlight = standaloneOpts.max_client_outstanding_reqs;
  opts.worker.sendTimeout = std::chrono::milliseconds{
    standaloneOpts.client_timeout_ms};
  if (!mcrouterOpts.debug_fifo_root.empty()) {
    opts.worker.debugFifoPath = getServerDebugFifoFullPath(mcrouterOpts);
  }

  /* Default to one read per event to help latency-sensitive workloads.
     We can make this an option if this needs to be adjusted. */
  opts.worker.maxReadsPerEvent = 1;

  try {
    LOG(INFO) << "Spawning AsyncMcServer";

    AsyncMcServer server(opts);
    server.installShutdownHandler({SIGINT, SIGTERM});

    auto router = McrouterInstance::init(
      "standalone",
      mcrouterOpts,
      server.eventBases());

    if (router == nullptr) {
      LOG(ERROR) << "CRITICAL: Failed to initialize mcrouter!";
      return false;
    }

    router->addStartupOpts(standaloneOpts.toDict());

    if (standaloneOpts.postprocess_logging_route) {
      router->setPostprocessCallback(getLogPostprocessFunc<void>());
    }

    if (standaloneOpts.enable_server_compression &&
        !mcrouterOpts.enable_compression) {
      initCompression(*router);
    }

    server.spawn(
      [router, &standaloneOpts] (size_t threadId,
                                 folly::EventBase& evb,
                                 AsyncMcServerWorker& worker) {
        serverLoop(*router, threadId, evb, worker, standaloneOpts);
      },
      [router]() {
        router->shutdown();
      }
    );

    server.join();

    LOG(INFO) << "Shutting down";

    McrouterInstance::freeAllMcrouters();

    if (!opts.unixDomainSockPath.empty()) {
      std::remove(opts.unixDomainSockPath.c_str());
    }
  } catch (const std::exception& e) {
    LOG(ERROR) << e.what();
    return false;
  }
  return true;
}
Beispiel #12
0
int
main(int argc, char *argv[])
{
    int rc, infinite = 0, count=0;
    FDType serverFD;

    processArgs(argc, argv);

    if (server) {
        serverLoop();
        fprintf(stderr, "oops server loop terminated\n");
    }

    if (!host) {
	usage();
        fprintf(stderr, "sockTestSrv: FAIL: please use -h to specify host\n");
        return 1;
    }
    printf("host = %s\n", host);

    if (!port) {
        fprintf(stderr, "must specify server port with -p\n");
        return 0;
    }
    printf("port = %d\n", port);


    rc = 1;
    if (clientAction == CMD) {
        serverFD = clientConnect(host, port);
        if (serverFD == -1) return 0;
        rc = cmdClient(serverFD);
        close(serverFD);
    } else if (clientAction == ECHO) {
        if (repeatCount == 0) { infinite = 1; count = 0; }
        while (1) {
            if (!infinite && repeatCount==0) {
                break;
            }
            serverFD = clientConnect(host, port);
            if (serverFD == -1) return 0;
            rc = echoClient(serverFD);
            close(serverFD);
            if (!infinite) {
                repeatCount--;
                write(1,".",1);
                if (repeatCount) {
                    doDelay();
                }
            } else {
                count++;
                if (count == 1000) {  write(1,".",1); count=0; }
                doDelay();
            }
        }
    } else {
        fprintf(stderr, "unknown client action\n");
        rc = 0;
    }
    return rc;
}
Beispiel #13
0
bool runServer(const McrouterStandaloneOptions& standaloneOpts,
               const McrouterOptions& mcrouterOpts) {
  AsyncMcServer::Options opts;

  if (standaloneOpts.listen_sock_fd >= 0) {
    opts.existingSocketFd = standaloneOpts.listen_sock_fd;
  } else if (!standaloneOpts.unix_domain_sock.empty()) {
    opts.unixDomainSockPath = standaloneOpts.unix_domain_sock;
  } else {
    opts.ports = standaloneOpts.ports;
    opts.sslPorts = standaloneOpts.ssl_ports;
    opts.pemCertPath = mcrouterOpts.pem_cert_path;
    opts.pemKeyPath = mcrouterOpts.pem_key_path;
    opts.pemCaPath = mcrouterOpts.pem_ca_path;
  }

  opts.numThreads = mcrouterOpts.num_proxies;

  opts.worker.connLRUopts.maxConns =
    (standaloneOpts.max_conns + opts.numThreads - 1) / opts.numThreads;
  opts.worker.versionString = MCROUTER_PACKAGE_STRING;
  opts.worker.maxInFlight = standaloneOpts.max_client_outstanding_reqs;
  opts.worker.sendTimeout = std::chrono::milliseconds{
    mcrouterOpts.server_timeout_ms};

  /* Default to one read per event to help latency-sensitive workloads.
     We can make this an option if this needs to be adjusted. */
  opts.worker.maxReadsPerEvent = 1;
  opts.worker.requestsPerRead = standaloneOpts.requests_per_read;

  try {
    LOG(INFO) << "Spawning AsyncMcServer";

    AsyncMcServer server(opts);
    server.installShutdownHandler({SIGINT, SIGTERM});

    auto router = McrouterInstance::init(
      "standalone",
      mcrouterOpts,
      server.eventBases());

    if (router == nullptr) {
      LOG(ERROR) << "CRITICAL: Failed to initialize mcrouter!";
      return false;
    }

    router->addStartupOpts(standaloneOpts.toDict());

    if (standaloneOpts.postprocess_logging_route) {
      router->setPostprocessCallback(getLogPostprocessFunc<void>());
    }

    server.spawn(
      [router, &standaloneOpts] (size_t threadId,
                                 folly::EventBase& evb,
                                 AsyncMcServerWorker& worker) {
        serverLoop(*router, threadId, evb, worker,
                   standaloneOpts.retain_source_ip);
      }
    );

    server.join();

    LOG(INFO) << "Shutting down";

    McrouterInstance::freeAllMcrouters();

    if (!opts.unixDomainSockPath.empty()) {
      std::remove(opts.unixDomainSockPath.c_str());
    }
  } catch (const std::exception& e) {
    LOG(ERROR) << e.what();
    return false;
  }
  return true;
}