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

  • Home
  • SEARCH
  • 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 7804187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:49:54+00:00 2026-06-02T01:49:54+00:00

If I send plain text there is no problem. Everything is ok. However If

  • 0

If I send plain text there is no problem. Everything is ok.
However If I try to send from the C# client an image, the server receives correct bytes number, but when I save the buffer to a file (in binary mode – wb), it always has 4 bytes.

I send it by the C# client by using the function File.ReadAllBytes().

My saving code looks like

   FILE * pFile;
   char *buf = ReceiveMessage(s);
   pFile = fopen (fileName , "wb");
   fwrite(buf, sizeof(buf[0]), sizeof(buf)/sizeof(buf[0]), pFile);
   fclose (pFile);
   free(buf);

My receiving function looks like

static unsigned char *ReceiveMessage(int s)
{
   int prefix;
   recv(s, &prefix, 4, 0);
   int len = prefix;
   char *buffer= (char*)malloc(len + 1);
   int received = 0, totalReceived = 0;
   buffer[len] = '\0';
   while (totalReceived < len)
   {
      if (len - totalReceived > BUFFER_SIZE)
      {
         received = recv(s, buffer + totalReceived, BUFFER_SIZE, 0);
      }
      else
      {
         received = recv(s, buffer + totalReceived, len - totalReceived, 0);
      }
      totalReceived += received;
   }

   return buffer;
}
  • 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-06-02T01:49:56+00:00Added an answer on June 2, 2026 at 1:49 am

    Your C code needs to pass len back from the ReceiveMessage() function.

    char *buf = ReceiveMessage(s);  // buf is a char*
    ... sizeof(buff)                // sizeof(char*) is 4 or 8
    

    So you’ll need something like

     static unsigned char *ReceiveMessage(int s, int* lenOut)
     {
         ...
         *lenOut = totalReceived ;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I send plain text emails using SmtpClient class, transfer encoding is set to
I have a script set up to send out multipart emails; plain text and
I've been working on Android program to send email with an attachment (text/plain)using Intent
I needed to send mail from my plain Flask app, so I thought the
I send data in this way: <form method=post enctype=text/plain action=Func> And I have a
I am try to send a mail from my php application.Mail send successfully but
Have a LINQ result, need to format it in plain text nicely to send
I'm using a plain old HTML form to send a post request to a
I send a mp3 file download url which was taken from database and mailed
I send data in JSON to the server like this: var username = $(#usernameField).val();

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.