473,328 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Read data from an asynchronous Socket

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
Dec 27 '06 #1
2 2197
The client side needs to do a Shutdown.Send so that the server can read
zero.

--
William Stacey [C# MVP]

"Giulio Petrucci" <gi*************@thisisafakedomain.comwrote in message
news:uN*************@TK2MSFTNGP06.phx.gbl...
| 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
Dec 27 '06 #2
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
Dec 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Darren Thomas | last post by:
Dear all, I have written a TCP server as a windows service that accepts connections using the System.Net.Sockets.Socket class. I use the various asynchronous methods in the socket class. I'm...
1
by: Niels Johansen | last post by:
Hello, When using the asynchronous read method in the BufferedStream class, , it seems to me that it blocks like the normal synchronous read method. Why is it so? Why does the...
5
by: Droopy Toon | last post by:
Hi, I am using asynchronous socket (BeginAccept for example). I tried to name each thread I am using but threads created by asynchronous Socket functions (like BeginAccept) creates "anonymous"...
3
by: Adie | last post by:
I'm using TcpClient in blocking mode with NetworkStreams and would like to be able to give notification that data was sent - I presume this must be possible? But anyone know how?
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
1
by: Alper AKCAYOZ | last post by:
Hello, I have developped asynchronous socket communication with blocking Socket commands (accept, connect, send, receive) by using threads on Windows .NET Forms. It is working properly. Now I...
6
by: Pat B | last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol using C#. I have implemented it using BeginReceive and EndReceive calls so as not to block when waiting for data from the...
2
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when...
3
by: Jason | last post by:
I am working on an asynchronous UDP socket server platform, and I am running into what appears to be a common problem but I have not found a good answer yet. If this was TCP, when the routine...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.