Note that there are some explanatory texts on larger screens.

plurals
  1. POSending HTML tag to browser via socket connection with C++ Socket API
    primarykey
    data
    text
    <p>I am trying to make a simple http server with C++. I've followed the <a href="http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#simpleserver" rel="nofollow">beej's guide</a> of network programming in C++. </p> <p>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.</p> <p>This is the code i wrote:</p> <pre><code>printf("Server: Got connection from %s\n", this-&gt;client_ip); if(!fork()) // This is the child process, fork() -&gt; Copy and run process { close(this-&gt;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&lt;h1&gt;Hello, client! Welcome to the Virtual Machine Web..&lt;/h1&gt;"; int length = strlen(message); // Plus 1 for null terminator int send_res = send(this-&gt;connection, message, length, 0); // Flag = 0 if(send_res == -1) { perror("send"); } close(this-&gt;connection); exit(0); } close(this-&gt;connection); // Parent doesn't need this; </code></pre> <p>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:</p> <pre><code>Content-Type: text/html; charset=ISO-8859-4 &lt;h1&gt;Hello, client! Welcome to the Virtual Machine Web..&lt;/h1&gt; </code></pre> <p>Not a big "Hello, client!.." string like a normally h1 tagged string. What is the problem? Am I missing something in the header?</p> <p>Another question is, why is the server won't running in port 80? The error log in server says:</p> <pre><code>server: bind: Permission denied server: bind: Permission denied Server failed to bind libc++abi.dylib: terminate called throwing an exception </code></pre> <p>Please help. Thank you. Edit: I'dont have any process on Port 80.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload