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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:36:13+00:00 2026-06-14T16:36:13+00:00

I am trying to make a simple http server with C++. I’ve followed the

  • 0

I am trying to make a simple http server with C++. I’ve followed the beej’s guide of network programming in C++.

When I ran the server in some port (8080, 2127, etc.) it successfully send response to browser (Firefox) when it accessed via address bar with: localhost:PORT_NUMBER except in port 80.

This is the code i wrote:

printf("Server: Got connection from %s\n", this->client_ip);

if(!fork()) // This is the child process, fork() -> Copy and run process
{
    close(this->server_socket); // Child doesn't need listener socket

    // Try to send message to client
    char message[] = "\r\nHTTP/1.1 \r\nContent-Type: text/html; charset=ISO-8859-4 \r\n<h1>Hello, client! Welcome to the Virtual Machine Web..</h1>";
    int length = strlen(message); // Plus 1 for  null terminator
    int send_res = send(this->connection, message, length, 0); // Flag = 0

    if(send_res == -1)
    {
        perror("send");
    }

    close(this->connection);

    exit(0);
}

close(this->connection); // Parent doesn't need this;

The problem is, even I have added the header on very early of the response string, why does the browser not showing the HTML properly instead shows only plain text? It shows something like this:

Content-Type: text/html; charset=ISO-8859-4

<h1>Hello, client! Welcome to the Virtual Machine Web..</h1>

Not a big “Hello, client!..” string like a normally h1 tagged string. What is the problem? Am I missing something in the header?

Another question is, why is the server won’t running in port 80? The error log in server says:

server: bind: Permission denied
server: bind: Permission denied
Server failed to bind
libc++abi.dylib: terminate called throwing an exception

Please help. Thank you. Edit: I’dont have any process on Port 80.

  • 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-14T16:36:15+00:00Added an answer on June 14, 2026 at 4:36 pm

    You need to terminate the HTTP response header with \r\n\r\n, rather than just \r\n. It should also start with something more like HTTP/1.1 200 OK\r\n, without the leading \r\n.

    For your port problem, if you have nothing else running on the port in question, you may find that the socket created by the last run of your program is still sticking around. To work around this, you can use setsockopt to set the SO_REUSEADDR flag on the socket. (This is not recommended for general use, I believe because you may receive data not intended for your program, but for development it’s extremely handy.)

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

Sidebar

Related Questions

I'm trying to make a simple http client server using java. It will show
I'm trying to make simple http server, that can be pause and resume,, I've
I am trying to make a simple HTTP server that would be able to
I'm trying to make a simple HTTP post a endpoint with ONLY url arguments.
I have another simple question about Node. I'm trying to make a simple http
I'm trying to make a simple HTTP client here , so i tried to
I'm trying everything to NAT traversal to make a HTTP(or others) server be accessible
I'm trying to make a simple text chat for example. Server start and work.
I am trying to make a very simple XML RPC Server with Python that
I'm trying to follow http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/ And have created a very simple example http://jsfiddle.net/6wbZQ/ It's

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.