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


C++ WebServer::is_running方法代码示例

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


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

示例1: file

TEST(conduit_io_websocket, websocket_test)
{
    if(! launch_server)
    {
        return;
    }


    
    // read png data into a string.
    // in the real example, we should have the png in memory
    std::string wsock_path = utils::join_file_path(CONDUIT_WEB_CLIENT_ROOT,
                                                   "wsock_test");

    std::string example_png_path = utils::join_file_path(wsock_path,
                                                         "example.png");

    CONDUIT_INFO("png path:" << example_png_path);
    std::ifstream file(example_png_path.c_str(),
                       std::ios::binary);

    // find out how big the png file is
    file.seekg(0, std::ios::end);
    std::streamsize png_raw_bytes = file.tellg();
    file.seekg(0, std::ios::beg);
    
    // use a node to hold the buffers for raw and base64 encoded png data
    Node png_data;
    png_data["raw"].set(DataType::c_char(png_raw_bytes));
    char *png_raw_ptr = png_data["raw"].value();
    
    // read in the raw png data
    if(!file.read(png_raw_ptr, png_raw_bytes))
    {
        // ERROR!
        CONDUIT_ERROR("DIDN'T READ ANYTHING");
    }

    // base64 encode the raw png data
    png_data["encoded"].set(DataType::char8_str(png_raw_bytes*2));
    
    utils::base64_encode(png_raw_ptr,
                         png_raw_bytes,
                         png_data["encoded"].data_ptr());

    // create the message we want to send.
    Node msg;
    msg["type"] = "image";
    // the goal is to drop this directly into a <img> element in our web client
    msg["data"] = "data:image/png;base64," + png_data["encoded"].as_string();
    // we will update the count with every send
    msg["count"] = 0;
    
    msg.to_json_stream("test.json","json");
    
    WebServer svr;
    // start our server
    svr.serve(wsock_path,8081);

    // this loop won't be necessary in the strawman lib.    
    while(svr.is_running()) 
    {
        utils::sleep(1000);
        
        // websocket() returns the first active websocket
        svr.websocket()->send(msg);
        // or with a very short timeout
        //svr.websocket(10,100)->send(msg);
        
        msg["count"] = msg["count"].to_int64() + 1;
    }
}
开发者ID:fedepad,项目名称:conduit,代码行数:72,代码来源:t_conduit_io_websocket.cpp


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