int client(int ac, char **av) { int port; int sock; fd_set fd_read; if (ac == 1) s_wait_server(&port, &sock); else if (ac == 3 && ft_isnumber(av[2])) { port = ft_atoi(av[2]); sock = ft_connect(av[1], port); } else return (ft_putendl(USAGE), 1); if (sock == -1) return (1); while (1) { if (ft_get_fd(&fd_read, sock) <= 0) break ; } close(sock); return (0); }
static void ft_cmd3(t_env *e, char cmd[], int fd, char **tab) { if (!e->clients[fd].connected) ft_connect(e, fd, cmd); else if (TEST && !ft_strcmp("prend", tab[0]) && tab[1]) preprend(e, fd, cmd); else if (TEST && !ft_strcmp("pose", tab[0]) && tab[1]) prepose(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("avance", cmd)) preavance(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("droite", cmd)) predroite(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("gauche", cmd)) pregauche(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("voir", cmd)) prevoir(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("inventaire", cmd)) preinventaire(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("incantation", cmd)) preincantation(e, fd, cmd); else if (e->clients[fd].i_action < 10 && !ft_strcmp("connect_nbr", cmd)) connect_nbr(e, fd); else if (TEST && !ft_strcmp("broadcast", tab[0]) && tab[1]) prebroadcast(e, fd, cmd); else ft_cmd4(e, cmd, fd); }
int ft_enable_comm(void) { if (test_info.ep_type == FI_EP_MSG) return pep ? ft_accept() : ft_connect(); else return ft_load_av(); }
t_client *init_client(char *addr, int port) { t_client *client; if (!(client = (t_client *)malloc(sizeof(t_client)))) { ft_error("client", __FILE__, __LINE__); return (NULL); } if ((client->sd = ft_socket()) == FT_ERROR) { ft_error("client", __FILE__, __LINE__); return (NULL); } if ((ft_connect(client->sd, addr, port)) == FT_ERROR) { ft_error("client", __FILE__, __LINE__); return (NULL); } return (init_client2(client, addr, port)); }
G_MODULE_EXPORT gboolean on_btnConnect_clicked(void) { char *host, *port; settimeout(0); /* alloced */ host = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cboHost)); if(!host){ status("Couldn't get host"); return FALSE; }else if(!*host){ status("To where am I to connect? Timbuktu?"); return FALSE; } if(cfg_add(host)) gtk_combo_box_insert_text(GTK_COMBO_BOX(cboHost), 0, host); port = strchr(host, ':'); if(port) *port++ = '\0'; if(ft_connect(&ft, host, port, callback)){ status("Couldn't connect: %s", ft_lasterr(&ft)); CLOSE(); }else{ status("Connected to %s", host); gstate = STATE_CONNECTED; settimeout(1); } URGENT(1); cmds(); g_free(host); return FALSE; }
void s_wait_server(int *port, int *sock) { char *line; char **spl; line = NULL; ft_putstr("Please choose a server [addr] [port] > "); while (ft_get_next_line(0, &line) > 0) { spl = ft_strsplit(line, ' '); if (ft_strlistlen(spl) == 2 && ft_isnumber(spl[1])) { *port = ft_atoi(spl[1]); *sock = ft_connect(spl[0], *port); if (*sock != -1) { ft_strlistdel(spl); return ; } } ft_putstr("Please choose a server [addr] [port] > "); ft_strlistdel(spl); } }
static int check_command(char *line, int *sock) { char **spl; int port; spl = ft_strsplit(line, ' '); if (ft_strlistlen(spl) > 0 && ft_strcmp(spl[0], "/connect") == '\0') { if (ft_strlistlen(spl) == 3 && ft_isnumber(spl[2])) { close(*sock); *sock = -1; port = ft_atoi(spl[2]); if ((*sock = ft_connect(spl[1], port)) != -1) { ft_strlistdel(spl); return (0); } s_wait_server(&port, sock); } } ft_strlistdel(spl); return (1); }