template <class ServerInterface> int Client<ServerInterface>::obtain_initial_references (const char *name) { try { // Initialize the naming services. if (naming_client_.init (orb_.in ()) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("[CLIENT] Process/Thread Id : (%P/%t) Unable to initialize ") ACE_TEXT ("the TAO_Naming_Client.\n")), -1); CosNaming::Name server_name (1); server_name.length (1); server_name[0].id = CORBA::string_dup (name); CORBA::Object_var obj = naming_client_->resolve (server_name); this->server_ = ServerInterface::_narrow (obj.in ()); if (CORBA::is_nil (this->server_.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Nil Server\n")), -1); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Client::obtain_initial_references"); return -1; } return 0; }
CommState URL_Tv_LoadHandler::Load() { OpStringC server_name(url->GetAttribute(URL::KUniHostName)); URL_LoadHandler::SetProgressInformation(REQUEST_FINISHED,0, server_name.CStr()); g_main_message_handler->PostMessage(MSG_COMM_LOADING_FINISHED, Id(), 0); return COMM_LOADING; }
int begin_response() { if (!client.response->headers) { error("Missing headers, adding new ones"); client.response->headers = new_headers(); } connection(client.response->headers,"close"); transfer_encoding(client.response->headers,"chunked"); server_name(client.response->headers,SERVER_VERSION); return client.response->contents || client.response->raw_contents; }
/* * Connects to specified server(s) * - @servers_count: the number of servers to be connected to * - @servers: a vector of Connection objects (for ip, port, pub_id) */ void Communication::Connect(int servers_count, std::vector<Connection> servers) { // connect with the server(s) for (int i=0; i<servers_count; i++) { boost::shared_ptr<boost::asio::ip::tcp::socket> sock(new boost::asio::ip::tcp::socket(*io_service_)); // get the pub from the options Connection con = servers[i]; boost::shared_ptr<std::string> server_name(new std::string(con.pub_id)); boost::shared_ptr<std::string> server_ip(new std::string(con.ip)); boost::shared_ptr<std::string> server_port(new std::string(con.port)); try { // try to connect boost::asio::ip::tcp::resolver resolver(*io_service_); boost::asio::ip::tcp::resolver::query query(con.ip, con.port); boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query); boost::asio::ip::tcp::endpoint endpoint = *iterator; sock->async_connect(endpoint, boost::bind(&Communication::AddServer, this, boost::asio::placeholders::error(), sock, endpoint, server_name, server_ip, server_port)); std::cout << "[" << boost::this_thread::get_id() << "] Connecting to: " << endpoint << std::endl; } // catch any exception catch (std::exception & ex) { std::cout << "[" << boost::this_thread::get_id() << "] Exception: " << ex.what() << std::endl; } } }
void CDBLB_ServiceMapper::GetServersList(const string& service, list<string>* serv_list) const { serv_list->clear(); SConnNetInfo* net_info = ConnNetInfo_Create(service.c_str()); SERV_ITER srv_it = SERV_Open(service.c_str(), fSERV_Standalone | fSERV_IncludeDown, 0, net_info); ConnNetInfo_Destroy(net_info); const SSERV_Info* sinfo; while ((sinfo = SERV_GetNextInfo(srv_it)) != NULL) { if (sinfo->time > 0 && sinfo->time != NCBI_TIME_INFINITE) { string server_name(CSocketAPI::ntoa(sinfo->host)); if (sinfo->port != 0) { server_name.append(1, ':'); server_name.append(NStr::UIntToString(sinfo->port)); } serv_list->push_back(server_name); } } SERV_Close(srv_it); }
int main(int argc, char **argv) { // Log arguments std::string args; if (argc != 0) { for (int i = 0; i < argc; i++) { if (i != 0) { args += " "; } args += argv[i]; } } else { args = "<none>"; } RLOG() << "Arguments: " << args.c_str(); // Seed random number generator srand((int)base::GetTickCount()); // Root of the pack cache std::string rootdir = ParseString(argc, argv, "--missionpack_dir"); std::string packdir = rootdir + "/pack"; std::string indexfile = rootdir + "/index"; std::string modfile = rootdir + "/modlist"; std::string badwordsfile = rootdir + "/badwords"; // Initialize the level info cache from the index so the server knows // the latest and greatest mission packs. wi::PackManager packm(packdir.c_str()); packm.WatchIndex(indexfile.c_str()); wi::LevelInfoCache cache(packm); // Submit main pack and packs from the index wi::NoCachePackFileReader pakr; if (pakr.Push(NULL, ParseString(argc, argv, "--htdata").c_str())) { wi::PackId packid; memset(&packid, 0, sizeof(packid)); packid.id = PACKID_MAIN; cache.Submit(pakr, packid); pakr.Pop(); } cache.SubmitIndex(indexfile); if (cache.empty()) { RLOG() << "cache is empty!"; exit(1); } // Set up StatsPoster base::SocketAddress stats_address(ParseString(argc, argv, "--stats_address").c_str()); std::string stats_path(ParseString(argc, argv, "--stats_path")); wi::StatsPoster stats(stats_address, stats_path); // Set up the server dword server_id = ParseDword(argc, argv, "--server_id"); bool checksync = FindArg(argc, argv, "--checksync"); RLOG() << "Sync checking turned " << (checksync ? "ON." : "OFF."); std::string log_file = ParseString(argc, argv, "--log_file"); wi::XMsgLog *xmsglog = NULL; if (log_file.size() != 0) { xmsglog = new wi::XMsgLog(log_file); } int max_players = ParseInteger(argc, argv, "--max_players", kcConnectedPlayersMax); int max_rooms = ParseInteger(argc, argv, "--max_rooms", kcRoomsMax); int max_games_per_room = ParseInteger(argc, argv, "--max_games_per_room", kcGamesPerRoomMax); int max_players_per_room = ParseInteger(argc, argv, "--max_players_per_room", kcPlayersPerRoomMax); wi::Server server(stats, xmsglog, cache, server_id, checksync, max_rooms, max_games_per_room, max_players_per_room, max_players, modfile, badwordsfile); base::SocketAddress listen_address = GetListenAddress(argc, argv); if (!server.Listen(listen_address)) { printf("Server failed to start.\n"); return 1; } listen_address = server.listen_address(); // Create default rooms dword result; server.lobby().NewRoom(NULL, "Main", "", wi::kroomidMain, wi::kfRmPermanent | wi::kfRmLocked, &result); server.lobby().NewRoom(NULL, "Main / Registered", "", wi::kroomidRegistered, wi::kfRmPermanent | wi::kfRmRegisteredOnly | wi::kfRmLocked, &result); server.lobby().NewRoom(NULL, "Main / Unmoderated", "", wi::kroomidUnmoderated, wi::kfRmPermanent | wi::kfRmLocked | wi::kfRmUnmoderated, &result); // Get the public_address. This is the address that gets sent in // ServerInfo. For example in AWS, the internal "private" ip // is not the same as the public one. If this is not present, // use the listen_address. base::SocketAddress public_address; std::string public_address_str = ParseString(argc, argv, "--public_address"); if (public_address_str.size() != 0) { public_address = base::SocketAddress(public_address_str.c_str()); } else { public_address = listen_address; } // Start up ServerInfoUpdater std::string server_info_path(ParseString(argc, argv, "--server_info_path")); std::string server_name(ParseString(argc, argv, "--server_name")); std::string server_location(ParseString(argc, argv, "--server_location")); std::string server_type(ParseString(argc, argv, "--server_type")); std::string server_info_extra(ParseString(argc, argv, "--server_info_extra")); dword expires = ParseDword(argc, argv, "--server_info_expires", 60 * 5); wi::ServerInfoUpdater updater(server, stats_address, server_info_path, server_id, server_name, server_location, server_type, public_address, server_info_extra, expires); server.SetUpdater(&updater); // Pump messages and wait for network i/o base::Thread::RunLoop(); return 0; }