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();










网友评论