int main(int argc, char **argv) { int c; settings_init(); while (-1 != (c = getopt(argc, argv, "h:" "i:" "p:" "m:" "c:" "n:" "b:" "s" "v" ))) { switch (c) { case 'h': usage(); exit(EXIT_SUCCESS); case 'i': settings.host = optarg; break; case 'p': settings.port = atoi(optarg); break; case 'm': settings.message = optarg; break; case 'c': settings.count = atol(optarg); break; case 'n': settings.no_of_threads= atoi(optarg); break; case 'b': settings.bufsize = atoi(optarg); break; case 's': settings.sctp = true; break; case 'v': settings.verbose = true; break; default: fprintf(stderr, "Illegal argument \"%c\"\n", c); exit(EXIT_FAILURE); } } echoClient(settings.host, settings.port, settings.message, settings.count, settings.no_of_threads); }
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; }