本文整理汇总了C++中NetworkNode::Initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkNode::Initialize方法的具体用法?C++ NetworkNode::Initialize怎么用?C++ NetworkNode::Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkNode
的用法示例。
在下文中一共展示了NetworkNode::Initialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadServers
void Server::loadServers(const std::string & path) {
// The add server lambda function:
auto addServer = [] (const std::string & host, const std::string & service) {
try {
NetworkNode node;
node.Initialize(host, service);
Network::AddNode(node);
} catch (std::exception & e) {
std::cerr << "[Server::loadServers::addServer] catch => std::exception" << std::endl;
std::cerr << "+ WHAT: " << e.what() << std::endl;
}
};
// Clear the current nodes:
Network::ClearNodes();
// Add the local node to the table:
auto & portNumber = Options::Get(Options::PortNumberKey);
addServer(LOCAL_HOST, portNumber);
// Load the lines inside the servers configuration file:
std::string line, address, port;
std::ifstream file(path);
while (std::getline(file, line)) {
// This is a Comma-separated values file:
std::stringstream sline(line);
bool ok = std::getline(sline, address, ',') &&
std::getline(sline, port, ',') &&
IsPortNumber(port);
if (ok) {
addServer(address, port);
} else {
std::cerr << "[Server::loadServers] Wrong line!" << std::endl;
std::cerr << "+ FILE: " << path << std::endl;
std::cerr << "+ LINE: " << line << std::endl;
}
}
}