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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:02:53+00:00 2026-05-18T02:02:53+00:00

I am making my own simple webserver and I have gotten text files and

  • 0

I am making my own simple webserver and I have gotten text files and html files to send perfectly, but when I try to send images, I am having some issues, and I can’t figure it out.

Here is what I have. I know sending one byte at a time is inefficient but it was for testing.

char buffer[1];
send_header(new_fd, get_file_type(file_location));
ifstream file;
file.open(temp.c_str(), ios::out | ios::binary);
while (file.good())
{
    file.read(buffer, sizeof(buffer));
 send(new_fd, buffer, strlen(buffer), 0);
}

Any ideas? Do I need to convert it to network byte order before I send?

Thanks!

  • 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-18T02:02:54+00:00Added an answer on May 18, 2026 at 2:02 am

    strlen(buffer) is going to count up to the first null character ('\0'), which is a very common byte in image data. You need to, instead, figure out how many bytes were actually read (ifstream.read() does not supply this information) and use that in place of your strlen call.

    EDIT: You can obtain this with ifstream.gcount() — so just replace your strlen call with file.gcount() and everything should magically work.

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

Sidebar

Related Questions

I'm making my own website using html and php, and a database using mysql
I would like to have a go at making some simple games for personal/learning
Im making a simple score keeping system and each user can have stats for
I'm creating small engine/framework for making games. It's kind of simple question but I
I'm developing a simple Qt 4 app and making my own dialog. I subclassed
I'm making my own Joomla template, but when I check menu manager, it seems
I am making an simple Blackery Berry app (widget) which uses simple HTML/JS to
I'm asking and answering my own question , but i'm not assuming i have
Since two days ago I started making my own simple classes from scratch, descended
I am making a simple CMS to use in my own blog and 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.