Receiving Encoding Chunked with Sockets Class

  • Thread starter Thread starter mwieder
  • Start date Start date
M

mwieder

Hi - I am using the .NET sockets class to build a web client.
Normally, to receive, I have the following code:
Byte[] RecvBytes = new Byte[16368];
Int32 bytes;
do
{
bytes = m_sock.Receive(RecvBytes, RecvBytes.Length, 0);
} while (bytes > 0);

However, if the transfer encoding of what is being sent is set to
"Chunked," this code hangs. How do I use the Socket class to receive a
chunked http request?
 
Hi - I am using the .NET sockets class to build a web client.
Normally, to receive, I have the following code:
Byte[] RecvBytes = new Byte[16368];
Int32 bytes;
do
{
bytes = m_sock.Receive(RecvBytes, RecvBytes.Length, 0);
} while (bytes > 0);

However, if the transfer encoding of what is being sent is set to
"Chunked," this code hangs. How do I use the Socket class to receive a
chunked http request?

Don't bother. Either use the built-in HttpWebRequest/HttpWebResponse which
understands chunked transfer encoding, or send a HTTP 1.0 request, which
doesn't permit chunked transfer encoding.

David
 
That's not an option here; I need to use the sockets class and it needs
to be 1.1 Asking me to change the requirements isn't a solution.
thanks.
 
That's not an option here; I need to use the sockets class and it needs
to be 1.1 Asking me to change the requirements isn't a solution.
thanks.

You are mistaking requirements with design. What you indicated is not a
requrement: it's a proposed impmlementation. If you have no other option,
all I can suggest is that you settle down with the spec
(http://www.ietf.org/rfc/rfc2616.txt) and get to it.

David
 
We need some lower level functionality that sockets provides which is
not available with the httpwebrequest object, so using sockets is a
requirement. The rfc spec doesn't help me code up C# to deal with a
chunked transfer encoding. If someone can be of help I would greatly
appreciate it.
 
We need some lower level functionality that sockets provides which is
not available with the httpwebrequest object, so using sockets is a
requirement.

Can you elaborate what these might be?

Cheers,
 
Can someone answer the question at hand which is how to handle transfer
encoding chunked in the sockets class? I'm not going to get into
adiscussion about using httpwebrequest or not.
 
Can someone answer the question at hand which is how to handle transfer
encoding chunked in the sockets class? I'm not going to get into
adiscussion about using httpwebrequest or not.

If someone approached you and said "what is the best method of
attaching two planks of wood, using a screw, but the only tool you're
allowed to use is a sledgehammer?", what would your reaction be?

It *may* be, that using the sledgehammer is the only approach. But that
is by no means certain. If you give your helpers additional help (bear
in mind, this help is free), they may be able to help further.

For instance, you've so far described your problem as needing more than
is offered by the simple built in web classes in .NET. But for all you
know, all your requirements are met by someone elses work. But they're
not going to waste an hour describing their solution if it's pointless.
Or we may know components that meet your solution (e.g. a
httpwebrequest that accepts an already open socket), but if we
recommend something that violates another of your rules, how are we to
know?

I'm guessing (from the fact that you have to deal with various HTTP
responses) that you're working in an Internet scenario, which leads me
(and many others probably) to wonder what low-level socket work you
have to do?

Damien
 
it doesn't really matter, does it? Now that you've totally hijacked
the thread into a discussion of newsgroup help, if someone approached
me and asked how to use the sledgehammer to get the job done, then I
would either help them if I could or keep my mouth shut if I couldn't.
Telling them to use a screwdriver when it's not an option is not
helpful.
 
Hello (e-mail address removed),
Can someone answer the question at hand which is how to handle
transfer encoding chunked in the sockets class? I'm not going to get
into adiscussion about using httpwebrequest or not.

Don't get me wrong, but RFC 2616 is pretty much all you'll get as a reference,
and if that's more than you can chew, rolling your own HTTP 1.1 stack might
not be the best idea...

(But yes, figuring out IETF RFCs is one of the worst jobs you can get in
software construction.)

What about using a different implementation like Indy or wrapping WinInet?

Cheers,
 
it doesn't really matter, does it? Now that you've totally hijacked
the thread into a discussion of newsgroup help, if someone approached
me and asked how to use the sledgehammer to get the job done, then I
would either help them if I could or keep my mouth shut if I couldn't.
Telling them to use a screwdriver when it's not an option is not
helpful.

But by not telling people *why* a screwdriver isn't an option you leave
them:

a) not knowing whether any intermediate solutions *might* be an option,
and
b) an unhelpful thread on Usenet if someone else comes along later with
a similar situation to yours.

Damien
 
Back
Top