Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:18:05+00:00 2026-05-31T08:18:05+00:00

I have a simple file transfer application, which transfers 4096 bytes per write from

  • 0

I have a simple file transfer application, which transfers 4096 bytes per write from the client. In the server end, I am using the following call read

tempLen = boost::asio::read(l_Socket, boost::asio::buffer(buf, bufSize), boost::asio::transfer_all(), error);

The templen is 1440 bytes, but when I read the buf, it is only 11 bytes. Copy pasting the server code below. I have tried both socket.read_some and asio::read – both end in same result. Can someone explain what am I doing wrong here?

//boost::array<char, 4096> buf;
char* buf = new char[4096];
char* bigBuffer = new char[2097152];
std::string strBuffer;

strBuffer.clear();

for (;;) // Loop for the whole file length
{

    boost::asio::read_until(l_Socket, request_buf, "\n\n");
    std::istream request_stream(&request_buf);
    request_stream >> bufSize;
    std::cout<< "Size of the Compressed data transfer:" << bufSize << "\n";

    // Clear the stream
    request_stream.clear();
    memset(bigBuffer, 0, 2097152);
    memset(buf, 0, 4096);

    if(bufSize == 0)
        break;

    size_t len = 0, prevLen = 0, tempLen = 0;

    try{

        //tempLen = l_Socket.read_some(boost::asio::buffer(buf, bufSize), error);
        tempLen = boost::asio::read(l_Socket, boost::asio::buffer(buf, bufSize), boost::asio::transfer_all(), error);
        std::cout << "Length from read: " << tempLen << " Buffer Size: " << bufSize << std::endl;
        prevLen = len;

        len += tempLen;

    }
    catch (boost::exception& e)
    {
         std::cerr << diagnostic_information(e);
    }.....}

Edit:

Just checked this problem is happening only when I send the data compressed with the following function at the client.

    std::string CClient::Compress(const char* data, unsigned int* dataLen)
{
    std::stringstream compressed;
    std::stringstream decompressed;
    std::cout << "From Compress Function: " << " Size of Decompressed Data: " << strlen(data) << std::endl;
    decompressed << data;
    boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
    out.push(boost::iostreams::zlib_compressor());
    out.push(decompressed);
    boost::iostreams::copy(out, compressed);
    *dataLen = compressed.str().size();
    return compressed.str();
}

std::string CClient::DeCompress(const std::string& data)
{
    std::stringstream compressed;
    std::stringstream decompressed;
    compressed << data;
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::zlib_decompressor());
    in.push(compressed);
    boost::iostreams::copy(in, decompressed);
    std::cout << "Decompressed Data: " << decompressed.str().c_str() << std::endl;
    return decompressed.str();
}

When I decompress the data at “the client” itself after compression(before sending), the data is getting printed properly. But when I read the data after receiving at the server, I am facing this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:18:07+00:00Added an answer on May 31, 2026 at 8:18 am

    The problem seems to be in the compression function. The string that gets returned from the Compression function, when I convert it in to c string, it terminates 11 bytes. I solved the problem by implementing the compression function to directly call zlib functions and handling data as char string rather than std::string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implement the simple TCP server and TCP client classes which can send
I have a simple cpp file which uses GIO. I have stripped out everything
In my app, I have a simple ASCII file which stores some config info
can anyone help? I have a simple html file which i am filling via
I am making simple one on server side & one on client side application
I need to write a simple file transfer protocol in C++ to upload or
I have a simple file transfer socket program where one socket sends file data
I have this pretty simple application, it uses a webService to transfer data to
I have a large application written using .Net remoting for file transfer. This was
I am trying to implement a very simple file transfer client in python using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.