The content-length value is application layer data.  That should be
separated from the transport layer (i.e. the layer that sends/receives the
data over TCP).

You could stream the data into the application data for processing before
all the data has been received; but, you should have transport layer logic
to receive all the data, regardless of its content.  Many browsers don't
play nice with servers that disconnect their socket before they finish
sending.

I wrote a TCP server a while back (in .NET 1.1) for SMTP.  Basically,
Socket.BeginReceive() was called in the accept callback and if
Socket.EndReceive returned more than 0 bytes BeginReceived was called
again.  I tested the Socket.Connected property before calling
BeginReceive; but, I don't remember if Connected is reliable or not.  It
basically followed the "Using an Asynchronous Server Socket" [1] example
in MSDN, except I did not mix application and transport logic (e.g. the
Console.WriteLine call in the read callback is application logic).  There
are other samples of Asynchronous sockets on MSDN but others mix
application and transport logic even more.

[1] http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpguide/html/cpconusingnon-blockingserversocket.asp

On Tue, 28 Mar 2006 13:16:39 -0600, Eric Means <[EMAIL PROTECTED]>
wrote:

>The client's request should include a Content-Length header. Your
webserver
>should continue waiting on data until it has read that number of bytes
(not
>including headers).
>
>It is legal for a client to send a portion of the request and pause an
>arbitrary amount of time before sending the rest; the length of the
message
>is not a TCP/IP parameter and so the Socket class doesn't know anything
>about it.
>
>AFAIK there is no way to make a single call to a framework method for what
>you want; you'll have to wrap it in a method of your own.
>
>On 3/28/06, Mike Andrews <[EMAIL PROTECTED]> wrote:
>>
>> Guys,
>>
>> I've been working on development of a webserver and I want to know how I
>> can
>> know that I have all of the data for a request.  If I post a form using
>> the
>> form's enctype attribute, the form is divided up (files and all) as
>> delimited sections.  However I don't seem to get all of the data.  I
loop
>> until the Socket.Available property returns 0, but that is not  the end
of
>> the data.  If I just sit for a couple seconds, more data appears and
then
>> more still.  How can I use a TCPListener blocking Accept() method to get
>> all
>> of the data and know that my request has completed?
>>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to