Read data from an asynchronous Socket

G

Giulio Petrucci

Hi everytbody,

I'm experiencing some problems trying to asynchronously read data from a
Socket object. What I do now is:
1) call th BeginReceive(...) method on the Socket object;
2) within the asynchronous callback method, call the EndReceive method,
getting the number of read bytes (stored in a variable called rb)
3) if (rb>0) I can suppose there are still some other bytes to be read,
so call again the BeginReceive(...) method, else performe what you need
to do. I sould implement an Http layer over this Socket (as I must be
"compliant" with fw1.1 I cannot use HttpWebRequest class :-((( ).

Testing thi small "server" I found this:
- sometimes it gots *stuck* trying to read from the client (Client-side
I've uset an HttpWebRequest and I've written the payload data on it's
RequestStream, but I used also a web form within my browser and I got
the same behaviour), that happens actually when the server shoud read 0
bytes... and the client gets disconnected (because of a timeout exceeded).

Can anyone help me? (if you need I can paste here some code).
Thanks in advance (and sorry for my English)!
Whishing you all a *great* 2007,
Giulio - from Italy
 
W

William Stacey [C# MVP]

The client side needs to do a Shutdown.Send so that the server can read
zero.

--
William Stacey [C# MVP]

| Hi everytbody,
|
| I'm experiencing some problems trying to asynchronously read data from a
| Socket object. What I do now is:
| 1) call th BeginReceive(...) method on the Socket object;
| 2) within the asynchronous callback method, call the EndReceive method,
| getting the number of read bytes (stored in a variable called rb)
| 3) if (rb>0) I can suppose there are still some other bytes to be read,
| so call again the BeginReceive(...) method, else performe what you need
| to do. I sould implement an Http layer over this Socket (as I must be
| "compliant" with fw1.1 I cannot use HttpWebRequest class :-((( ).
|
| Testing thi small "server" I found this:
| - sometimes it gots *stuck* trying to read from the client (Client-side
| I've uset an HttpWebRequest and I've written the payload data on it's
| RequestStream, but I used also a web form within my browser and I got
| the same behaviour), that happens actually when the server shoud read 0
| bytes... and the client gets disconnected (because of a timeout exceeded).
|
| Can anyone help me? (if you need I can paste here some code).
| Thanks in advance (and sorry for my English)!
| Whishing you all a *great* 2007,
| Giulio - from Italy
 
G

Giulio Petrucci

Hi William,

first of all, thank you for your reply.

William Stacey [C# MVP] ha scritto:
The client side needs to do a Shutdown.Send so that the server can read
zero.

but on the client side I'm using an HttpWebRequest, so the only thing
that I can d (nad that I actually *do*) is
HttpWebRequest.GetRequestStream().Close().
Shutdown.Send is Socket-involved, right? How can I shut down my
HttpWebRequest object underlying Socket?

Thank you in advance,
Giulio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top