Example #1
0
bool Server::connect_router_after()
{
    bind_and_connect();
    connect_login();
    connect_db();
    return true;
}
int Login_Client_Messager::process_block(Block_Buffer &buf) {
	LOGIN_MANAGER->add_recv_bytes(buf.readable_bytes());

	int32_t cid = 0;
	int16_t len = 0;
	int32_t msg_id = 0;
	int32_t status = 0;
	int32_t serial_cipher = 0;
	int32_t msg_time_cipher = 0;
	buf.read_int32(cid);
	buf.read_int16(len);
	buf.read_int32(msg_id);
	buf.read_int32(status);
	buf.read_int32(serial_cipher);
	buf.read_int32(msg_time_cipher);

	LOGIN_MANAGER->add_msg_count(msg_id);
	switch (msg_id) {
	case REQ_CONNECT_LOGIN:{
			connect_login(cid, msg_id, buf);
			break;
	}
	default:	{
		LOG_ERROR("error msg_id:%d", msg_id);
		break;
	}
	}

	return 0;
}
Example #3
0
void Server::connect_login()
{
    ip::tcp::resolver resolver(m_io_service);
    ip::tcp::resolver::iterator it = resolver.resolve( {"127.0.0.1", "9800"} );


    m_login_conn.reset(new LoginConn(m_io_service));
    async_connect(m_login_conn->socket(), it,
        [this] (const err_code& ec, ip::tcp::resolver::iterator it_)
        {
            if (!ec)
            {
                cout << "connected login!" << endl;

                int id = allocate_conn_id();
                m_login_conn->connect(id);
            }
            else
            {
                std::cout << "error. try connect login..." << std::endl;
                boost::asio::deadline_timer t(m_io_service, boost::posix_time::seconds(10));
                t.wait();
                connect_login();
            }
        });
}