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 4250544
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:32:33+00:00 2026-05-21T04:32:33+00:00

Hey, im making a simple program that sends/receives files, my code sends text files

  • 0

Hey, im making a simple program that sends/receives files, my code sends text files but when it comes to binary it starts to bug, code:

static void
send_event(conn,file)
  void *conn;
  void *file;
{
   FILE *f;
   char *buffer;
   int32_t block_size;
   int32_t size;
   size_t __read;
   ConnectionQueue *q;
   f = (FILE *)file;
   q = (ConnectionQueue *)conn;
   block_size = conf_getint("transfer:block_size");
   if (block_size <= 1 || block_size > 1024)
     {
       abort();
       return;
     }
   buffer = (char *)MyMalloc(block_size);
   if (!q || !f)
     return;

   fseek(f,0L,SEEK_END);
   size = ftell(f);
   if (size == 0L)
     {
       send_socket(q->conn,"RECEIVE: 302 FSE");
       return;
    }
   fseek(f,0,SEEK_SET);
   while (true)
    {
      if (q->abort)
       {
         send_socket(q->conn,"RECEIVE: File transfer aborted\n");
         if (f)
           fclose(f);
         f = NULL;
         MyFree(buffer);
         return;
       }
      __sleep(100);
       __read = fread(buffer,sizeof(char),512,f);
       if (__read <= 0)
         {
           send_socket(q->conn,"RECEIVE: EOF\n");
           break;
         }
      if (*buffer == '\0')
        {
          send_socket(q->conn,"RECEIVE: EOF\n");
          break;
        }

      send_socket(q->conn,"RECEIVE: %s\n",buffer);
   }
   send_socket(q->conn,"RECEIVE: 915 EOF\n");
   fclose(f);
   f = NULL;
   MyFree(buffer);
}

FIXED: Please check my answer \/

  • 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-21T04:32:33+00:00Added an answer on May 21, 2026 at 4:32 am

    this fixed it -> Send binary file in HTTP response using C sockets

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

Sidebar

Related Questions

Hey so i'm making a simple text game using the pdCurses library and a
hey, am making a program that makes the forms and controls dynamically from xml
Hey, I'm making a simple user friendly css editor using Prototype. Anyway, I was
hey guys having this really simple problem but cant seem to figure out have
Hey all, this should be a simple task but for some reason i am
Hey guys i'm making a website but for some reason my div tags are
Hey so i'm making a function that gathers up sprites that you wanna keep
Hey so I'm making a factoring program and I'm wondering if anyone can give
Hey i am making a simple search machine through alot of different coloumns in
Hey all, I think this might be a bug, but it's killing me. I

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.