Networking Forums

Networking Forums > Computer Networking > Linux Networking > linux socket programming and HTTP Protocol Problem

Reply
Thread Tools Display Modes

linux socket programming and HTTP Protocol Problem

 
 
PGHULME
Guest
Posts: n/a

 
      08-17-2006, 08:28 PM
Hi

I have started writing an app(in c and compiled with gcc) that delivers

html pages (aptly named a web server). my current code for sending the
http header and code looks like this:
// send header
send(clntSocket, "HTTP/1.1 200 OK\n", 16, 0);
send(clntSocket, "Content-type: text/html\n", 25, 0);
send(clntSocket, "Content-length:\n\n", 18, 0); //extra line feed for
http spec
//html code
send(clntSocket, "<HTML>", 6, 0);
send(clntSocket, "<HEAD>", 6, 0);
send(clntSocket, "<TITLE>", 7, 0);
send(clntSocket, "A Small Hello", 13, 0);
send(clntSocket, "</TITLE>", 8, 0);
send(clntSocket, "</HEAD>", 7, 0);
send(clntSocket, "<BODY>", 6, 0);
send(clntSocket, "<H1>Hi</H1>", 11, 0);
send(clntSocket, "<P>This is very minimal hello world HTML
document.</P>", 55, 0);
send(clntSocket, "</BODY>", 7, 0);
send(clntSocket, "</HTML>", 7, 0);
//close socket
close(clntSocket);


this is just to test the socket connection. The problem is, i try to
use internet explorer or firefox to connect to the server and retrieve
this test page. Both web browsers connect to the server but both fail
to load the page. Internet explorer complains that it cannot find
server. and firefox says that the connection was reset before the page
could be loaded. The thing is though, if i use wget to connect to the
server, it does manage to download the test page correctly. I have read

through the http specs, and they say that the header should be sent
followed by a new line (/n) then the data/html, once this is sent the
connection should then be closed. I have followed those specs but i am
unable to see why the code works when wget is connecting but not when
web browsers try.... anyone got any ideas????

 
Reply With Quote
 
 
 
 
Jeroen Geilman
Guest
Posts: n/a

 
      08-21-2006, 09:35 PM
PGHULME wrote:
> Hi
>
> I have started writing an app(in c and compiled with gcc) that delivers
>
> html pages (aptly named a web server). my current code for sending the
> http header and code looks like this:
> // send header
> send(clntSocket, "HTTP/1.1 200 OK\n", 16, 0);
> send(clntSocket, "Content-type: text/html\n", 25, 0);
> send(clntSocket, "Content-length:\n\n", 18, 0); //extra line feed for
> http spec
> //html code
> send(clntSocket, "<HTML>", 6, 0);
> send(clntSocket, "<HEAD>", 6, 0);
> send(clntSocket, "<TITLE>", 7, 0);
> send(clntSocket, "A Small Hello", 13, 0);
> send(clntSocket, "</TITLE>", 8, 0);
> send(clntSocket, "</HEAD>", 7, 0);
> send(clntSocket, "<BODY>", 6, 0);
> send(clntSocket, "<H1>Hi</H1>", 11, 0);
> send(clntSocket, "<P>This is very minimal hello world HTML
> document.</P>", 55, 0);
> send(clntSocket, "</BODY>", 7, 0);
> send(clntSocket, "</HTML>", 7, 0);
> //close socket
> close(clntSocket);
>
>
> this is just to test the socket connection. The problem is, i try to
> use internet explorer or firefox to connect to the server and retrieve
> this test page. Both web browsers connect to the server but both fail
> to load the page. Internet explorer complains that it cannot find
> server. and firefox says that the connection was reset before the page
> could be loaded. The thing is though, if i use wget to connect to the
> server, it does manage to download the test page correctly. I have read
>
> through the http specs, and they say that the header should be sent
> followed by a new line (/n) then the data/html, once this is sent the
> connection should then be closed. I have followed those specs but i am
> unable to see why the code works when wget is connecting but not when
> web browsers try.... anyone got any ideas????


Telnet to the server, and manually issue the GET command.
If the result is equal to what you would expect then it does not lie in
the headers, or content - you have messed up the HTTP conversation, and
wget is merely very very forgiving.

J
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
some problem in UDP programming under linux s9327620@csie.cyut.edu.tw Linux Networking 4 02-27-2007 03:16 AM
Can any one help me!! (Socket Programming) girishdomain@gmail.com Linux Networking 8 05-25-2005 04:17 PM
Linux kernel socket programming Shuang Liang Linux Networking 2 04-07-2005 12:38 AM
Http Client Side Programming --- Any Libraries Avl. Sriram Linux Networking 4 06-03-2004 02:04 PM
linux socket programming sank Linux Networking 2 01-02-2004 05:36 PM



1 2 3 4 5 6 7 8 9 10 11