add:服务端打印本机所有的IP地址。
This commit is contained in:
		
							parent
							
								
									9b8af77bcf
								
							
						
					
					
						commit
						ae330a8fc5
					
				@ -24,6 +24,21 @@ CTcpServer::~CTcpServer()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool CTcpServer::start(unsigned short port)
 | 
					bool CTcpServer::start(unsigned short port)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    asio::ip::tcp::resolver resolver(io_context_);
 | 
				
			||||||
 | 
					    asio::ip::tcp::resolver::query query(asio::ip::host_name(), "");
 | 
				
			||||||
 | 
					    asio::ip::tcp::resolver::iterator it = resolver.resolve(query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    logger_->debug("Here are the local IP addresses you may.");
 | 
				
			||||||
 | 
					    logger_->debug("===========================================");
 | 
				
			||||||
 | 
					    int i = 1;
 | 
				
			||||||
 | 
					    while (it != asio::ip::tcp::resolver::iterator()) {
 | 
				
			||||||
 | 
					        asio::ip::address addr = it->endpoint().address();
 | 
				
			||||||
 | 
					        logger_->info("({}){}", i, addr.to_string());
 | 
				
			||||||
 | 
					        ++it;
 | 
				
			||||||
 | 
					        ++i;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    logger_->debug("===========================================");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port);
 | 
					    asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port);
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        acceptor_.open(endpoint.protocol());
 | 
					        acceptor_.open(endpoint.protocol());
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user