美文网首页
c++传输图片(不断更新)

c++传输图片(不断更新)

作者: 送分童子笑嘻嘻 | 来源:发表于2020-02-28 21:00 被阅读0次

while (true) {
if (file_index == time_count) {
continue;
}
time_count++;
this_thread::sleep_for(std::chrono::milliseconds(1000));
mutex.lock();
string filename_2 = file_dir + to_string(cartographer::src::file_index) + ".pgm";
char filename_buf[filename_2.size()];
strcpy(filename_buf, filename_2.c_str());
std::cout << "send_map_data-filename_2=" << filename_2 << std::endl;

            std::cout << "send_map_data-connect=has file" << std::endl;

            //time_count++;
            // 连接服务器
            boost::system::error_code ec;
            socket.connect(ep, ec);
            // 如果出错,打印出错信息
            if (ec) {
                std::cout << boost::system::system_error(ec).what() << std::endl;
            }


            ifstream fin( filename_buf );
            std::ifstream ifs(filename_buf, ios::in|ios::binary|ios::ate);
            long size = ifs.tellg();
            char *p = new char[size];
            ifs.seekg(0, ios::beg);
            ifs.read(p, size);
            ifs.close();

            //添加数据数量的协议
            socket.write_some(buffer(p,size), ec);
            socket.close();
            mutex.unlock();

相关文章

网友评论

      本文标题:c++传输图片(不断更新)

      本文链接:https://www.haomeiwen.com/subject/agbrhhtx.html