/* * * */ int Network::connectToSocket(std::string host, std::string port) { ClientInfo *stranger = new ClientInfo(_len); int id; if (!stranger) return (false); stranger->setAddr(AF_INET, port.c_str(), host.c_str()); //prépare la connexion udp vers un serveur if (UDPDuplicate(stranger, id)) // verificationd des duplicats return (id); new_connected(++_id, stranger); return (_id); }
int Network::connectSocket(std::string host, std::string port) { struct protoent *pe; ClientInfo *stranger = new ClientInfo(_len); if (!stranger) return (0); if (!(pe = getprotobyname("TCP"))) return (0); stranger->setAddr(_family, port.c_str(), host.c_str()); //prépare la connexion tcp vers un serveur if ((stranger->get_socket() = socket(_family, SOCK_STREAM, pe->p_proto)) == -1) return (0); if (connect(stranger->get_socket(), (saddr *)(&stranger->get_info()), sizeof(saddrin)) < 0) { close(stranger->get_socket()); delete stranger; return (0); } new_connected(++_id, stranger); _change = true; return (_id); }