Esempio n. 1
0
server::server(const ios_deque& io_services, int port, std::string interface_address)
  : io_services_(io_services),
  endpoint_(interface_address.empty()?	
      (ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)): // INADDR_ANY for v4 (in6addr_any if the fix to v6)
      ba::ip::tcp::endpoint(ba::ip::address().from_string(interface_address), port) ),	// specified ip address
  acceptor_(*io_services.front(), endpoint_)	// By default set option to reuse the address (i.e. SO_REUSEADDR)
{
  std::cout << endpoint_.address().to_string() << ":" << endpoint_.port() << std::endl;
  start_accept();
}
/**
 * Initialize all needed data
 *
 * @param io_service reference to io_service
 * @param port port to listen on, by default - 10001
 */
	server(const ios_deque& io_services, int port=10001)
		: io_services_(io_services),
		  acceptor_(*io_services.front(),
					ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)) {
		start_accept();
	}