コード例 #1
0
ファイル: data_server.cpp プロジェクト: Tushar-Naik/hpcl
void
DataServer::on_client_created( const SocketPtr &in_client ) {
    in_client->signal_data_received().connect( boost::bind(
                    std::mem_fn(&DataServer::on_data_received),
                    this, _1, _2));
    m_server->signal_client_created().connect( boost::bind(
                        std::mem_fn( &DataServer::on_client_disconnect),
                        this, _1 ));
}
コード例 #2
0
ファイル: client.cpp プロジェクト: Tushar-Naik/hpcl
int main() 
try {
    SocketFactoryPtr factory = SocketFactory::create_factory();
    SocketPtr socket = factory->create_socket( true );
    socket->signal_data_received().connect( handle_data );
    socket->signal_remote_disconnect().connect( handle_stop );
    socket->connect_to_server( "127.0.0.1", 1024 );
    while( true )
    {
        {
            std::lock_guard<std::mutex> l(g_stop_mutex);
            if( g_stop )
            {
                socket->shutdown();
                break;
            }
        }
        std::string msg;
        std::cout<<"say? ";
        getline( std::cin, msg );
        if( "QUIT" == msg )
        {
            std::lock_guard<std::mutex> l(g_stop_mutex);
            g_stop = true;
            socket->shutdown();
        }
        else if( "STOPLISTENER" == msg )
        {
            send_data( socket, msg );
            socket->shutdown();
            std::lock_guard<std::mutex> l(g_stop_mutex);
            g_stop = true;
        }
        else
        {
            send_data( socket, msg );
        }
    }
    return 0;
}
catch( boost::exception &error ) {
    int const *errorNo
                = boost::get_error_info<boost::errinfo_errno>( error );
    std::cerr<<"Error occurred [" <<strerror(*errorNo) <<"]"<<std::endl;
    return -1;
}
catch( std::exception &e ) {
    std::cerr<<"Error occurred [" <<e.what() <<"]"<<std::endl;
    return -1;
}
コード例 #3
0
void
RemoteLogServer::on_create( const SocketPtr &in_socket ) {
    in_socket->signal_data_received().connect( boost::bind(
                std::mem_fn( &RemoteLogServer::on_log_received), this, _1, _2));
}