/** ** Initialize the TCP connection to the Meta Server. ** ** @return -1 fail, 0 success. ** @todo Make a dynamic port allocation. */ int MetaInit() { const int port_range_min = 1234; const int port_range_max = 1244; for (int i = port_range_min; i < port_range_max; ++i) { MetaServerFildes = NetOpenTCP(CNetworkParameter::Instance.localHost.c_str(), i); if (MetaServerFildes != static_cast<Socket>(-1)) { if (NetConnectTCP(MetaServerFildes, NetResolveHost(MasterHost), MasterPort) != -1) { break; } MetaServerFildes = static_cast<Socket>(-1); } } if (MetaServerFildes == static_cast<Socket>(-1)) { return -1; } if (SendMetaCommand("Login", "") == -1) { return -1; } char *reply = NULL; if (RecvMetaReply(&reply) == -1) { return -1; } if (MetaServerOK(reply)) { delete[] reply; return 0; } else { delete[] reply; return -1; } }
bool Connect(const CHost &host) { return NetConnectTCP(socket, host.getIp(), host.getPort()) != -1; }