471,326 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Http server - Header problem

Hi,
I need to have a simple http server in one of my applications. It's
just for a little text data so i wanted to write my own.
So i have a listener on port 80 and i'm using async methods to receive
/ send data. My problem is, i found lots of sample web server
applications, all of them just calls socket.read method for 1-4kb data.
And parses the response for headers. Isn't it possible to receive
partial data from socket and break this method? I mean i do telnet
google.com:80 and write my request, server doesn't respond till i send
double newline.
What would you suggest? Just read once and go or check received data
for CRLF+CRLF?

Dec 14 '05 #1
1 1647
> What would you suggest? Just read once and go or check received data
for CRLF+CRLF?
No, there is no warranty that one read will bring you whole request.

you have to read until CRLF+CRLF is encountered. But it is not the end. this
approach will be suffice only for GET requests as there is no content
following...
if you issue POST requests then you have to obtain HTTP header ( ends with
double CRLF ) and then find field Content-Length and its value.

Then read until you receive Content-Length bytes of the info.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

<an*****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... Hi,
I need to have a simple http server in one of my applications. It's
just for a little text data so i wanted to write my own.
So i have a listener on port 80 and i'm using async methods to receive
/ send data. My problem is, i found lots of sample web server
applications, all of them just calls socket.read method for 1-4kb data.
And parses the response for headers. Isn't it possible to receive
partial data from socket and break this method? I mean i do telnet
google.com:80 and write my request, server doesn't respond till i send
double newline.
What would you suggest? Just read once and go or check received data
for CRLF+CRLF?

Dec 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Peter Gaunt | last post: by
7 posts views Thread by Michael Foord | last post: by
1 post views Thread by John Smith | last post: by
8 posts views Thread by Andreas Klemt | last post: by
14 posts views Thread by Chris Fink | last post: by
reply views Thread by Nico Ploner | last post: by
7 posts views Thread by shadowman | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.