예제 #1
0
void
Socket::connect(const ao::ip::tcp::endpoint & e)
{
    socket_.open(e.protocol());
    socket_.connect(e);

    std::cout << "Connected to '" << e << "'" << std::endl;
}
예제 #2
0
파일: server.cpp 프로젝트: hatc/image-proxy
Server::Server(ip::tcp::endpoint endpoint, Server::ConnectionCtor ctor)
  : acceptor(io_service), image_cache(new ImageCache(0x100)), task_pool(new TaskPool()), ctor(ctor), stop(false) {
  new_connection.reset(ctor(io_service, image_cache, task_pool));

  acceptor.open(endpoint.protocol());
  acceptor.set_option(ip::tcp::acceptor::reuse_address(true));
  acceptor.bind(endpoint);
  acceptor.listen();
  acceptor.async_accept(new_connection->Socket(),
    boost::bind(&Server::handle_accept, shared_from_this(), boost::asio::placeholders::error));
}
	PrivateData( int portNumber ) :
		m_success(false),
		m_endpoint(tcp::v4(), portNumber),
		m_service(),
		m_acceptor( m_service ),
		m_thread()
	{
		m_acceptor.open(  m_endpoint.protocol() );
		m_acceptor.set_option( boost::asio::ip::tcp::acceptor::reuse_address(true));
		m_acceptor.bind( m_endpoint );
		m_acceptor.listen();
		m_success = true;
	}
예제 #4
0
void http_server_base::bind_listen(boost::system::error_code & ec, boost::asio::ip::tcp::endpoint ep)
{
	accept_opt->open(ep.protocol(), ec);
	if (ec)
		return;
	accept_opt->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true), ec);
	if (ec)
		return;
	accept_opt->bind(ep, ec);
	if (ec)
		return;
	accept_opt->listen(boost::asio::socket_base::max_connections, ec);
}
예제 #5
0
void CommandServer::createTcpEndpoint()
{
    std::stringstream streamForPort;
    streamForPort << m_options.port;

    Ip::tcp::resolver resolver(m_tcpAcceptor.get_io_service());
    // TODO: support ipv6
    Ip::tcp::resolver::query query(Ip::tcp::v4(),
                                   m_options.host,
                                   streamForPort.str(),
                                   Ip::resolver_query_base::numeric_service);
    Ip::tcp::endpoint endpoint = *resolver.resolve(query);

    m_tcpAcceptor.open(endpoint.protocol());
    m_tcpAcceptor.set_option(Ip::tcp::acceptor::reuse_address(true));
    m_tcpAcceptor.bind(endpoint);
    m_tcpAcceptor.listen();

    LOG(info) << "Listening on " << endpoint;

    startAcceptOnTcp();
}
예제 #6
0
void Server::start_accept_connections_on(boost::asio::ip::tcp::endpoint endpoint)
{
    using namespace boost::asio;

    // Acceptors used to listen for incoming connections over ip::tcp.
    IpTcpConnectionAcceptor_ptr acceptor( new IpTcpConnectionAcceptor(io_service_) );

    // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
    acceptor->open( endpoint.protocol() );
    acceptor->set_option( ip::tcp::acceptor::reuse_address(true) );
    acceptor->bind(endpoint);
    acceptor->listen();

    // The next connection to be accepted.
    ConnectionIpTcp_ptr next_connection( new ConnectionIpTcp(io_service_, request_handler_) );
    acceptor->async_accept( next_connection->socket(),
                            boost::bind(&Server::handle_accept,
                                        this,
                                        acceptor,
                                        next_connection,
                                        placeholders::error)
                           );
}