Пример #1
0
int main()
{
    InetAddress inetAddress(36911);

    boost::asio::io_service _io_service;
    TcpServer server(inetAddress, _io_service);

    EventHandler eventHandler;
    server.setNewConnectCallback(
        boost::bind(&EventHandler::NewConnectionHandler, &eventHandler, _1, _2)
        );

    server.start();

    system("pause");
    return 0;
}
Пример #2
0
int main()
{
    try
    {
        EventHandler eventHandler;
        InetAddress inetAddress(36911);

        //boost::asio::io_service io_service;
        IOService service;
        TcpServer server(inetAddress, service, 4);

        server.setNewConnectionCallback(
            std::bind(&EventHandler::NewConnectionHandler, &eventHandler, std::placeholders::_1, std::placeholders::_2)
        );

        server.setWriteCompletedCallback(
            std::bind(&EventHandler::WriteCompletedHandler, &eventHandler, std::placeholders::_1, std::placeholders::_2)
        );

        server.setReadCompletedCallback(
            std::bind(&EventHandler::ReadCompletedHandler, &eventHandler, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
        );

        server.setConnectionClosedCallback(
            std::bind(&EventHandler::ConnectionClosed, &eventHandler, std::placeholders::_1)
        );

        server.start();
    }
    catch (...)
    {
        std::cout << "exception occurred" << std::endl;
    }

    return 0;
}