int main(int argc, char **argv) { int argcc,port,i; int ret=0; argcc = argc; port = client_setup(&context, &argcc, argv); if (remote_name == NULL) { remote_name = get_default_username (); if (remote_name == NULL) errx (1, "who are you?"); } for (i = argcc;i < argc; i++) { char message[128]; ret = doit (argv[i], port, service, message, sizeof(message)); if(ret == 0) warnx ("%s: ok", argv[i]); else warnx ("%s: failed: %s", argv[i], message); } return(ret); }
int main (int argc, char *argv[]) { ros::init(argc,argv,"UDPClient"); ros::NodeHandle n; client_sock_id = socket(SOCK_FAMILY,SOCK_TYPE,SOCK_FLAG); if(client_sock_id < 0) { ROS_INFO("Error! - Socket Creation Error\n"); exit(0); } client_setup(); ROS_INFO("Waiting for data to come from lower layer\n"); while (ros::ok()) { int status = -1; socklen_t servAddr = sizeof(servAddr); send_buf = (char *)malloc(MAX_BUF_SIZE); // scanf("%s",send_buf); //take data from lower layer status = sendto(server_sock_id,send_buf,strlen(send_buf)+1,0, (struct sockaddr *)&servAddr,&servAddr); if(status < 0) { ROS_INFO("Error! - Read Error"); } ROS_INFO("Sent Data : %s",recv_buf); ros::spinOnce(); loop_rate.sleep(); } close(client_sock_id); return 0; }
int main(int argc, char **argv) { krb5_context context; /* XXX */ int port = client_setup(&context, &argc, argv); return client_doit (argv[argc], port, service, proto); }
int main(int argc, char *argv[]) { context_t c; mrp_clear(&c); if (!parse_cmdline(&c, argc, argv)) exit(1); mrp_log_set_mask(c.log_mask); mrp_log_set_target(c.log_target); if (c.server) mrp_log_info("Running as server, using D-BUS '%s'...", c.busaddr); else mrp_log_info("Running as client, using D-BUS '%s'...", c.busaddr); c.ml = mrp_mainloop_create(); mrp_add_sighandler(c.ml, SIGINT , signal_handler, &c); if (c.server) server_setup(&c); else client_setup(&c); mrp_mainloop_run(c.ml); if (c.server) server_cleanup(&c); else client_cleanup(&c); return 0; }
void create_client(Window win, XWindowAttributes *attr) { struct client *c, *tc; c = client_create(win, attr); tc = find_client_by_trans(mons, win); client_setup(c, selmon, mons, tc); rules_apply(c); client_map_window(c); client_move_resize(c, c->x, c->y, c->w, c->h, true, true); monitor_add_client(c->mon, c); }
/******************************************************************************* * Function name: INT main(INT argc, CHAR, **argv) * Parameters: argc - number of arguments * **argv - array of arguments * Returns: 0 on success * < 0 on failure * Description: Assumes client if one argument is incuded on startup, else * server. Initiates the server/client setup respectively. *******************************************************************************/ int main(int argc, char **argv) { char *machine; struct hostent *hostp; if (argc == 1) { /* Start as a server */ printf("Server\n"); return server_setup(); } else if (argc == 2){ /* Start as client */ printf("Client\n"); machine = argv[1]; /* Get machine */ int retVal = client_setup(machine); return retVal; } printf("Invalid argument count"); return -1; }
int main(int argc, char **argv) { init_log(L_INFO); if (!(state = client_setup())) { return -1; } uint8_t r = 0, g = 0, b = 0; long last_ms = 0; int rs; do { struct timespec spec; clock_gettime(CLOCK_MONOTONIC, &spec); long ms = round(spec.tv_nsec / 1.0e6); cairo_set_source_rgb(state->cairo, r, g, b); cairo_rectangle(state->cairo, 0, 0, 100, 100); cairo_fill(state->cairo); rs = client_render(state); if (ms - last_ms > 100) { r++; if (r == 0) { g++; if (g == 0) { b++; } } ms = last_ms; } } while (rs); client_teardown(state); return 0; }
static int run(void) { char *node, *service; uint64_t flags; int ret; size_t i; ret = ft_read_addr_opts(&node, &service, hints, &flags, &opts); if (ret) return ret; ret = opts.dst_addr ? client_setup() : server_setup(); if (ret) { fprintf(stderr, "error: %s\n", fi_strerror(-ret)); return ret; } /* Leave extra space for invalid size test */ cm_data = calloc(1, cm_data_size + 1); if (!cm_data) return -FI_ENOMEM; entry = calloc(1, sizeof(*entry) + cm_data_size); if (!entry) return -FI_ENOMEM; if (opts.dst_addr) { ret = ft_sock_connect(opts.dst_addr, sock_service); if (ret) goto err2; } else { ret = ft_sock_listen(sock_service); if (ret) goto err2; ret = ft_sock_accept(); if (ret) goto err1; } for (i = 1; i <= cm_data_size; i <<= 1) { printf("trying with data size: %zu\n", i); if (opts.dst_addr) ret = client(i); else ret = server(i); if (ret) goto err1; ret = ft_sock_sync(0); if (ret) goto err1; } /* Despite server not being setup to handle this, the client should fail * with -FI_EINVAL since this exceeds its max data size. */ if (opts.dst_addr) { printf("trying with data size exceeding maximum: %zu\n", cm_data_size + 1); /* Don't call client since it produces an error message. */ ret = client_connect(cm_data_size + 1); if (ret != -FI_EINVAL) { FT_ERR("expected -FI_EINVAL, got: [%d]:%s\n", ret, fi_strerror(-ret)); } else { ret = FI_SUCCESS; } } err1: ft_sock_shutdown(sock); err2: free(entry); return ret; }
int main(int argc, char **argv) { int i, cc; char msg[MSG_BFR_SZ]; char tag[MSG_BFR_SZ]; struct player_data *p = NULL; --argc; ++argv; setbuf(stdout, NULL); setbuf(stdin , NULL); if (!client_setup(&argc, &argv)) return EXIT_FAILURE; recv(msg); sscanf(msg, "%*s %d", &SELF.id); sprintf(msg, "NAME %s", BOT_NAME); send(msg); while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "READY")) break; else if (!strcmp(tag, "PLAYERS")) { sscanf(msg, "%*s %u", &numplayers); for (i = 0, p = players; i < numplayers; ++i, ++p) { recv(msg); sscanf(msg, "%u %u", &p->id, &p->pool); p->wager = p->card = p->active = 0; } } else if (!strcmp(tag, "CARDS")) sscanf(msg, "%*s %u %u", &XRANGE, &XDUP); else if (!strcmp(tag, "ANTE")); sscanf(msg, "%*s %*d %u", &ROUNDS_TO_DBL); } if (!p) EXPECTED(tag, "PLAYERS"); copyself(); game_setup(players, numplayers); while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "ENDGAME")) break; else if (!strcmp(tag, "ROUND")) { unsigned int rnum, pstart, rante; sscanf(msg, "%*s %u %u %u", &rnum, &pstart, &rante); copyself(); round_start(rnum, pstart, rante); while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "TURN")) { for (i = 0, p = players; i < numplayers; ++i, ++p) { recv(msg); sscanf(msg, "%u %u %u %u %u", &p->id, &p->card, &p->pool, &p->wager, &p->active); } copyself(); recv(tag); if (strcmp(tag, "GO")) EXPECTED(tag, "GO"); int k = player_turn(players, numplayers); // perform the chosen action switch (k) { case CALL: sprintf(msg, "CALL"); break; case FOLD: sprintf(msg, "FOLD"); break; default: sprintf(msg, "WAGER %d", k); break; } send(msg); } else if (!strcmp(tag, "ENDROUND")) { int winnings; sscanf(msg, "%*s %u", &winnings); for (i = 0, p = players; i < numplayers; ++i, ++p) { recv(msg); p->wager = p->active = 0; sscanf(msg, "%u %u %u", &p->id, &p->card, &p->pool); } copyself(); round_end(players, numplayers, winnings); break; } // got an unexpected message... else EXPECTED(tag, "TURN/ENDROUND"); } } // got an unexpected message... else EXPECTED(tag, "ROUND/ENDGAME"); } game_end(); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int i, cc; char msg[MSG_BFR_SZ]; char tag[MSG_BFR_SZ]; struct player_data *p = NULL; --argc; ++argv; setbuf(stdout, NULL); setbuf(stdin , NULL); struct timeval tv; gettimeofday(&tv, NULL); if (!client_setup(&argc, &argv)) return EXIT_FAILURE; recv(msg); sscanf(msg, "%*s %d", &SELF.id); sprintf(msg, "NAME %s", BOT_NAME); send(msg); srand(tv.tv_usec+SELF.id); while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "READY")) break; else if (!strcmp(tag, "BOARD")) sscanf(msg, "%*s %u", &BOARDSIZE); else if (!strcmp(tag, "PLAYERS")) { sscanf(msg, "%*s %u", &NUMPLAYERS); for (i = 0, p = players; i < NUMPLAYERS; ++i, ++p) { p->id = i; p->lastscore = p->score = 0; } } else if (!strcmp(tag, "ROUNDS")) sscanf(msg, "%*s %u", &NUMROUNDS); } copyself(); game_setup(players); unsigned int rnum; while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "ENDGAME")) break; else if (!strcmp(tag, "ROUND")) { unsigned int rnum; sscanf(msg, "%*s %u", &rnum); while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "GO")) break; else EXPECTED(tag, "GO"); } copyself(); player_turn(rnum, players); clamp(&SELF.cow.x, 0, BOARDSIZE); clamp(&SELF.cow.y, 0, BOARDSIZE); clamp(&SELF.fence1.x, 0, BOARDSIZE); clamp(&SELF.fence2.x, SELF.fence1.x, BOARDSIZE); clamp(&SELF.fence1.y, 0, BOARDSIZE); clamp(&SELF.fence2.y, SELF.fence1.y, BOARDSIZE); sprintf(msg, "MOVE %u %u %u %u %u %u" , SELF.cow.x, SELF.cow.y , SELF.fence1.x, SELF.fence1.y , SELF.fence2.x, SELF.fence2.y ); send(msg); while ((cc = recv(msg))) { sscanf(msg, "%s", tag); if (!strcmp(tag, "NEXT")) break; else if (!strcmp(tag, "PLAYER")) { sscanf(msg, "%*s %d", &i); p = &players[i]; sscanf(msg, "%*s %*d %u %u %u %u %u %u %u %u" , &p->cow.x, &p->cow.y , &p->fence1.x, &p->fence1.y , &p->fence2.x, &p->fence2.y , &p->lastscore, &p->score ); } } } // got an unexpected message... else EXPECTED(tag, "ROUND/ENDGAME/MOVE/UPDATE"); } quit: game_end(); return EXIT_SUCCESS; }