int main(int argc,char **argv) { //0.parse cmdline if(argc<2) { printf("Usage: %s <filename>.\n",argv[0]); exit(0); } int sockfd; struct sockaddr_in server; //1.create socket if((sockfd = socket(AF_INET,SOCK_STREAM,0))<0) ERR("Socket failed"); //2.connect to server struct hostent *hostent = gethostbyname(SERVERHOST); CLEAR(server); server.sin_family = AF_INET; server.sin_port = htons(SERVERPORT); memcpy(&server.sin_addr,hostent->h_addr,sizeof(server.sin_addr)); //inet_pton(AF_INET,SERVERIP,&server.sin_addr); if(connect(sockfd,(struct sockaddr*)&server,sizeof(server))<0) ERR("Connect failed"); //3.read/write doServer(sockfd,argv[1]); //4.close close(sockfd); return 0; }
int main (int argc, char *argv[]) { ELF_LOADED_SIG int msock; /* master server socket */ int ssock; /* master server socket */ int portN; /* port number to listen */ /*if (argc != 2) { usage (argv[0]); } portN = atoi (argv[1]);*/ portN = 10000; msock = serversock (SOCK_STREAM, portN, 5); struct sockaddr_in fromAddr; /* the from address of a client */ unsigned int fromAddrLen; /* from-address length */ fromAddrLen = sizeof (fromAddr); printf ("Waiting for connection\n"); ssock = accept (msock, (struct sockaddr *) &fromAddr, &fromAddrLen); if (ssock < 0) { if (errno != EINTR) { errmesg ("accept error\n"); } } printf ("Connection recv'd\n"); while (doServer (ssock) > 0) {}; close (ssock); close (msock); return 0; } // end fn main
int main(int ac, char **av) { int ch; int i; int serverMode = 0; while ((ch = getopt(ac, av, "aW:T:C:sv")) != -1) { switch(ch) { case 'a': /* auto tag / standard broadcast */ addTag(&AddrBase, NULL, 0); break; case 'W': /* specify working directory */ WorkDir = optarg; break; case 'T': TagDir = optarg; break; case 'C': /* specify server config file(s) (colon delimited) */ ConfigFiles = optarg; break; case 's': /* run as server using config file */ serverMode = 1; break; case 'v': VerboseOpt = 1; break; default: usage(1); /* not reached */ } } for (i = optind; i < ac; ++i) { if (strchr(av[i], '=')) addTag(&VarBase, av[i], 0); else addTag(&AddrBase, av[i], 0); } if (AddrBase == NULL) usage(1); if (AddrBase && AddrBase->name == NULL && AddrBase->next) { fprintf(stderr, "You cannot specify both -a AND a list of hosts. If you want\n" "to use auto-broadcast mode with a tag other than 'auto',\n" "just specify the tag without a host, e.g. ':<tag>'\n"); exit(1); } if (serverMode) doServer(); else doClient(); return(0); }
void startAllSystems(char **argv) { int k; int status; char writeBuffer[MSGLENGTH]; //fork to act as sms sender if((messagesPid=fork())==0) { strncpy(argv[0],"sms",argv0size); messagesPid=getpid(); doMessageHandler(); wait(&status); exit(0); } my_printf("sms sender pid %d\n",messagesPid); handleMessage(0,0,0,0,"SYSTEM STARTING",0,ALARM_NO_STORE); for(k=0;k<TOTALSYSTEMS;k++) forkSystem(k,argv); //fork to act as controller if((controllerPid=fork())==0) { strncpy(argv[0],"controller",argv0size); controllerPid=getpid(); doController(); wait(&status); exit(0); } my_printf("controller pid %d\n",controllerPid); //fork to act as a server if((serverPid=fork())==0) { strncpy(argv[0],"server",argv0size); serverPid=getpid(); doServer(); wait(&status); exit(0); } my_printf("server pid %d\n",serverPid); }
/** * The main procedure. * @param argc The command line. * @param argv The number of options in the command line. * @retval EXIT_SUCCESS Upon successful termination. * @retval EXIT_FAILURE When an error occurs. */ int main(int argc, char **argv) { int port, fifo, listener_socket; if (argc != 2) { usage(argv[0]); return EXIT_FAILURE; } port = atoi(argv[1]); if (port <= 0 || port > 65535) { usage(argv[0]); return EXIT_FAILURE; } if (mkfifo(FIFO_NAME, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) if (errno != EEXIST) { perror("Create fifo:"); exit(EXIT_FAILURE); } if ((fifo = TEMP_FAILURE_RETRY(open(FIFO_NAME, O_RDWR))) < 0) { perror("Open fifo:"); exit(EXIT_FAILURE); } if (sethandler(sigint_handler, SIGINT)) { ERR("Setting SIGINT:"); } if (sethandler(sig_update_handler, SIGRTMIN + 11)) { ERR("Setting SIGRTMIN+11:"); } listener_socket = bind_inet_socket(port, SOCK_STREAM); doServer(listener_socket, fifo); if (TEMP_FAILURE_RETRY(close(listener_socket)) < 0) { ERR("Close:"); } if (TEMP_FAILURE_RETRY(close(fifo)) < 0) { ERR("Close fifo:"); } if (TEMP_FAILURE_RETRY(unlink(FIFO_NAME)) < 0) { ERR("Unlink fifo:"); } printf("Server has terminated normally.\n"); return EXIT_SUCCESS; }
/* PURPOSE: To secure port 'PORT_NUMBER' to listen to clients, to make * 'NUM_CLIENTS' POSIX threads to handle that number of clients, to * display the number of chars processed by either thread as they are * processed, and to close windowing, mutex locking and the socket when * finished. Returns EXIT_SUCCESS on succes or EXIT_FAILURE otherwise. */ int main () { int socketDs; int clientIn; int clientIn1; pthread_t clientThread[NUM_CLIENTS]; if ( (socketDs = startServer()) == -1 ) { fprintf(stderr,"Error connecting to socket.\n"); return(EXIT_FAILURE); } startWindow(); int connectDs = accept(socketDs,NULL,NULL); doServer(connectDs); stopWindow(); stopServer(socketDs); return(EXIT_SUCCESS); }
void newMessage() { new_message = oslLoadImageFilePNG("system/app/messenger/new_message.png", OSL_IN_RAM, OSL_PF_8888); if (!new_message) debugDisplay(); while (!osl_quit) { LowMemExit(); oslStartDrawing(); oslClearScreen(RGB(0,0,0)); controls(); oslDrawImageXY(new_message, 0, 0); navbarButtons(2); battery(330,2,0); digitaltime(381,4,0,hrTime); androidQuickSettings(); volumeController(); oslDrawImage(cursor); if (osl_keys->pressed.L) { oslPlaySound(Lock, 1); lockscreen(); } if (osl_keys->pressed.circle) { oslDeleteImage(new_message); messenger(); } if ((cursor->x >= 444 && cursor->x <= 480) && (cursor->y >= 157 && cursor->y <= 213) && (osl_keys->pressed.cross)) { oslPlaySound(KeypressStandard, 1); oslDeleteImage(messengerbg); messenger(); } if ((cursor->x >= 444 && cursor->x <= 480) && (cursor->y >= 76 && cursor->y <= 155) && (osl_keys->pressed.cross)) { oslPlaySound(KeypressStandard, 1); oslDeleteImage(messengerbg); home(); } if ((cursor->x >= 444 && cursor->x <= 480) && (cursor->y >= 19 && cursor->y <= 75) && (osl_keys->pressed.cross)) { oslPlaySound(KeypressStandard, 1); multitask(); } captureScreenshot(); if (cursor->x >= 7 && cursor->x <= 435 && cursor->y >= 55 && cursor->y <= 86 && osl_keys->pressed.cross) { oslPlaySound(KeypressStandard, 1); doServer(); } oslIntraFontSetStyle(Roboto, fontSize, BLACK, 0, INTRAFONT_ALIGN_LEFT); oslDrawString(14, 245, tempMessage); if (cursor->x >= 10 && cursor->x <= 362 && cursor->y >= 228 && cursor->y <= 270 && osl_keys->pressed.cross) { oslPlaySound(KeypressStandard, 1); openOSK("Enter Message", "", 128, -1); } if ((cursor->x >= 10 && cursor->x <= 405 && cursor->y >= 88 && cursor->y <= 118 && osl_keys->pressed.cross) && oslIsWlanPowerOn()) doClient(); else if ((cursor->x >= 410 && cursor->x <= 442 && cursor->y >= 92 && cursor->y <= 118 && osl_keys->pressed.cross) && oslIsWlanPowerOn()) doServer(); oslEndDrawing(); oslEndFrame(); oslSyncFrame(); } }
int main(int argc, char **argv) { int rank = 0; command_name = argv[0]; parse_opt(argc, argv); if (arg_version) { printVersion(); return 0; } if (arg_cp) { unsigned int slen = strlen(copy_command_src) + strlen(arg_cp) + 1000; char *icmd = malloc(slen); snprintf(icmd, slen,"%s %s", copy_command_src, arg_cp); arg_icmd = icmd; arg_ocmd = copy_command_dest; fprintf(stderr, " input command: %s\n", arg_icmd); } if (arg_icmd && arg_ifile) { fprintf(stderr, "Warning: Ignoring -icmd %s, because -i is set\n", arg_icmd); arg_icmd = NULL; } if (arg_ocmd && arg_ofile) { fprintf(stderr, "Warning: Ignoring -ocmd %s, because -o is set\n", arg_ocmd); arg_ocmd = NULL; } if (PSP_Init() != PSP_OK) { fprintf(stderr, "PSP_Init() failed!\n"); exit(1); } if (!arg_manual) { /* HACK HACK HACK */ setenv("__PSI_MASTERNODE", "-1", 0); setenv("__PSI_MASTERPORT", "-1", 0); PSE_initialize(); rank = PSE_getRank(); } else if (arg_server) { rank = 1; } if (rank < 0) { /* original process, let's spawn rank 0 and become logger */ setenv("PSI_NOMSGLOGGERDONE", "", 1); PSE_spawnAdmin(-1, 0, argc, argv, 0); } else if (rank == 0) { /* server */ if (arg_progress) set_timer(1, 1 ,timer); doServer(); } else { /* client */ if (arg_progress && arg_manual) set_timer(1, 1 ,timer); doClient(); } if (!arg_manual) { PSI_release(PSC_getMyTID()); } if ((!rank || arg_manual) && arg_progress) { print_stat(1); } return 0; }