当前位置: 首页>>代码示例>>C++>>正文


C++ Host::get_count_and_add方法代码示例

本文整理汇总了C++中Host::get_count_and_add方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::get_count_and_add方法的具体用法?C++ Host::get_count_and_add怎么用?C++ Host::get_count_and_add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Host的用法示例。


在下文中一共展示了Host::get_count_and_add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: process_command

void IRC_Client::process_command(std::string command, Host & host)
{
	std::smatch result;
	std::string datagram_id = host.get_name();
    if (std::regex_search(command, result, std::regex("^CONNECT ([\\w\\d]+)\\s+(\\d+)$")))
    { // precisa de DNS
    	datagram_id = datagram_id + "." + std::to_string(host.get_count_and_add());
    	std::string content = std::string(result[1]) + " A IN";
    	host.add_to_send_datagram_queue(Datagram(host.ip_, host.dns_server_ip_, new UDP_Segment(DNS_CLIENT_PORT, DNS_SERVER_PORT, content), datagram_id));
    	commands_waiting_for_dns.push_back(command);
    }
    else if (std::regex_search(command, result, std::regex("^CONNECT ([\\d\\.]+)\\s+(\\d+)$")))
    { // não precisa de DNS
    	datagram_id = datagram_id + "." + std::to_string(host.get_count_and_add());
    	std::string content = "CONNECT";
    	std::string destination_ip = result[1];
    	int destination_port = stoi(result[2]);
    	std::string source_ip = host.ip_;
    	int source_port = IRC_CLIENT_PORT;

    	host.add_to_send_datagram_queue(Datagram(source_ip, destination_ip, new UDP_Segment(source_port, destination_port, content), datagram_id));
    }
    else if (std::regex_search(command, result, std::regex("^USER ([\\w\\d]+)$"))
    	|| std::regex_search(command, result, std::regex("^QUIT$")))
    {
    	if (!connected_server_ip.empty() && connected_server_port != -1)
    	{
    		datagram_id = datagram_id + "." + std::to_string(host.get_count_and_add());
	    	std::string source_ip = host.ip_;
	    	int source_port = IRC_CLIENT_PORT;
	    	std::string destination_ip = connected_server_ip;
	    	int destination_port = connected_server_port;
	    	host.add_to_send_datagram_queue(Datagram(source_ip, destination_ip, new UDP_Segment(source_port, destination_port, command), datagram_id));
	    }
	    else
	    	printf("Cliente IRC não conectado a nenhum servidor\n");
    }
    else
    	printf("Comando desconhecido no %s\n", host.get_name().c_str());
}
开发者ID:Tuiuiu,项目名称:MAC0448-EP3,代码行数:40,代码来源:irc_client.cpp

示例2: receive_datagram

void IRC_Server::receive_datagram(Datagram datagram, Host & host)
{
	std::smatch result;
    std::string datagram_id = host.get_name();
	std::string message = datagram.get_message();
    if (std::regex_search(message, result, std::regex("^CONNECT$"))
    	|| std::regex_search(message, result, std::regex("^USER [\\w\\d]+$"))
    	|| std::regex_search(message, result, std::regex("^QUIT$"))
    	)
    {
        datagram_id = datagram_id + "." + std::to_string(host.get_count_and_add());
    	std::string source_ip = host.ip_;
        int source_port = IRC_SERVER_PORT;
		std::string destination_ip = datagram.get_source_ip();
        int destination_port = datagram.get_source_port();
		std::string content = ":" + host.get_name() + " " + message;
    	host.add_to_send_datagram_queue(Datagram(source_ip, destination_ip, new UDP_Segment(source_port, destination_port, content), datagram_id));
    }
}
开发者ID:Tuiuiu,项目名称:MAC0448-EP3,代码行数:19,代码来源:irc_server.cpp


注:本文中的Host::get_count_and_add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。