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


C++ socket::remote_endpoint方法代码示例

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


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

示例1: LOG

void L2Socket::HandleAccept( tcp::socket& _socket, boost::system::error_code _ec )
{
    if (!acceptor->is_open() )
    {
        LOG( "HandleAccept acceptor !is_open()!!!" );
        return ;
    }
    if( _ec )
    {
        LOG( "HandleAccept error: "+ _ec.message() );
        Disconnect(_socket);
        return;
    }
    LOG( "HandleAccept New Connect ip: "+_socket.remote_endpoint().address().to_string() + " port: " + _socket.remote_endpoint().port());
    
    //tcp::no_delay option(true);
    //_socket.set_option(option);

    shared_ptr<L2Actor> _act = L2_GET_UNUSED_OBJ(L2Actor);
    
    SERVER->PushActor( _act->OID );
    
    _act->GetAgent()->SetConnect(true);
    sockAry.push_back(&_socket);
    agentOIDAry.push_back( _act->GetAgent()->OID );
    
    if( bWebSocket )
        OnHandshake(_socket,_act->GetAgent()->OID);
    else
        OnReceive( _socket,_act->GetAgent()->OID );
    
    //THREAD->ThreadSleepFPS();
    OnAccept();
}
开发者ID:LockeLin,项目名称:WebSocket_server,代码行数:34,代码来源:socket.cpp

示例2: catch

		Client(int id_given, tcp::socket* tcp_socket_given)
		{
			id = id_given;
			queue = "";
			queue_active = false;
			connected = false;
			active = false;
			broken = false;
			expected_datagram = 0;
			min_fifo_size = max_fifo_size = 0;
			tcp_socket = tcp_socket_given;
			
			try {
				address = tcp_socket->remote_endpoint().address().to_string();
				port = tcp_socket->remote_endpoint().port();
			} catch (bs::system_error e) {
				broken = true;
			}
		}
开发者ID:tomciokotar,项目名称:Sound-Broadcaster,代码行数:19,代码来源:server.cpp

示例3: run

void CMD_bye::run(tcp::socket& s)
{
  boost::asio::ip::udp::endpoint p;
  p.address(s.remote_endpoint().address());
  p.port(43201);
  vector<Observer>::iterator it = find(observers.begin(), observers.end(),
				       Observer(p, id));
  it->reg(false);
  it->set_id(-1);
  reply(s, "OK BYE");
}
开发者ID:snyh,项目名称:WHMon,代码行数:11,代码来源:cmd.cpp

示例4: find

void L2Socket::Disconnect(tcp::socket& _socket,size_t _agentOID)
{
    //return;
    if( _agentOID != -1 )
    {
        UIntAry::iterator _it = find( agentOIDAry.begin(),agentOIDAry.end(),_agentOID );
        
        if( _it != agentOIDAry.end() )
        {
            shared_ptr<L2Agent> agt = L2_FIND_OBJ(L2Agent, _agentOID);
            agt->Disconnect();
            agentOIDAry.erase( _it );
            
            LOG( "Disconnect !!! ip: "+_socket.remote_endpoint().address().to_string()+" port: "+ _socket.remote_endpoint().port() );
        }
    }
    else
        LOG( "Disconnect !!!" );
    _socket.close();
    SocketAry::iterator _it = find( sockAry.begin(),sockAry.end(),&_socket );
    
    if( _it != sockAry.end() )  sockAry.erase( _it );
}
开发者ID:LockeLin,项目名称:WebSocket_server,代码行数:23,代码来源:socket.cpp

示例5: session_thread

void session_thread(tcp::socket sock) {
    std::stringstream threadName;
    threadName << sock.remote_endpoint();
    loguru::set_thread_name(threadName.str().c_str());
    auto db = Storage::Mongo::MongoBackend{
        "mongodb://localhost",
        "directory",
        "rootdn",
        "dc=mongodb,dc=com"
    };

    bool noAuthentication = false;
    // Put this into its own scope so the YAML nodes get cleaned up.
    {
        auto check = config["noAuthentication"];
        if (check && check.as<bool>() == true)
            noAuthentication = true;
    }

    bool userBound = false;
    std::string userBoundDN;

    for (;;)
    {
        std::vector<uint8_t> header(2);;
        size_t length;
        asio::error_code error;

        length = sock.read_some(asio::buffer(header), error);
        if (error) {
            if (error == asio::error::eof)
                break;
            else
                throw asio::system_error(error);
        }
        if (length != header.size()) {
            LOG_F(ERROR, "Client sent malformed BER header");
            break;
        }

        std::vector<uint8_t> reqBuffer;
        reqBuffer.reserve(1024);
        if ((header[1] & 128) != 0) {
            header[1] -= 128;
            reqBuffer.resize(header[1]);
            length = sock.read_some(asio::buffer(reqBuffer), error);
            if (length != reqBuffer.size()) {
                LOG_F(ERROR, "Client sent mal-formed BER size header");
                break;
            }
            auto decodedReqSize = Ber::decodeInteger(reqBuffer.cbegin(), reqBuffer.cend());
            reqBuffer.resize(decodedReqSize, 0);
        } else {
            reqBuffer.resize(header[1], 0);
        }
        length = sock.read_some(asio::buffer(reqBuffer), error);
        if (length != reqBuffer.size()) {
            LOG_F(ERROR, "Client sent fewer bytes than expected");
            break;
        }

        auto ber = Ber::Packet::decode(header[0], reqBuffer);
        auto messageId = static_cast<uint64_t>(ber.children[0]);
        auto messageType = Ldap::MessageTag { static_cast<Ldap::MessageTag>(ber.children[1].tag) };

        Ldap::MessageTag errorResponseType;
        switch (messageType) {
        case Ldap::MessageTag::SearchRequest:
            errorResponseType = Ldap::MessageTag::SearchResDone;
            break;
        default:
            errorResponseType = static_cast<Ldap::MessageTag>(static_cast<uint8_t>(messageType) + 1);
            break;
        }
        try {
            if (messageType == Ldap::MessageTag::BindRequest) {
                Ldap::Bind::Request bindReq(ber.children[1]);
                if (bindReq.type == Ldap::Bind::Request::Type::Sasl) {
                // TODO SUPPORT SASL BINDS!
                    throw Ldap::Exception(Ldap::ErrorCode::authMethodNotSupported);
                }

                bool passOkay = false;
                if (noAuthentication) {
                    LOG_S(INFO)
                        << "Authentication is disabled, sending bogus bind for "
                        << bindReq.dn;
                    passOkay = true;
                } else {
                    LOG_S(INFO) << "Authenticating " << bindReq.dn;
                    try {
                        auto entry = db.findEntry(bindReq.dn);
                        for (const auto& pass: entry->attributes.at("userPassword")) {
                            passOkay = Password::checkPassword(bindReq.simple, pass);
                            if (passOkay)
                                break;
                        }

                    } catch (Ldap::Exception e) {
                        LOG_S(ERROR) << "Error during authentication " << e.what();
//.........这里部分代码省略.........
开发者ID:jbreams,项目名称:nfldap,代码行数:101,代码来源:main.cpp


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