BeginReceive return zero length buffer when run ,and work correctly when use step by step debug mode
- From: "semedao" <semedao@xxxxxxxxxxxxxxxx>
- Date: Fri, 15 Sep 2006 14:25:12 +0200
Hi , I am using asyc sockets p2p connection between 2 clients.
when I debug step by step the both sides , i'ts work ok.
when I run it , in somepoint (same location in the code)
when I want to receive 5 bytes buffer , I call the BeginReceive and then
wait on AsyncWaitHandle.WaitOne()
but it is signald imidiatly , and the next call to EndReceive return zero
bytes length , also the buffer is empty.
here is the code:
public static byte[] Receive(Socket OpenSocket, int length)
{
byte[] buffer = new byte[length];
int totalreceive = 0;
int _lastReceive = 0;
if (OpenSocket.Blocking)
totalreceive = OpenSocket.Receive(buffer);
else
{
IAsyncResult ar;
do
{
//in this point the OpenSocket.Available == 0 !
ar = OpenSocket.BeginReceive(buffer, 0, length, SocketFlags.None, null,
null);
ar.AsyncWaitHandle.WaitOne(); // something "signald it before data received?
_lastReceive = OpenSocket.EndReceive(ar);
if (_lastReceive == 0) // happen when run the code , doeas not happen if
step by step slowly!
{
buffer = null;
throw new Exception("No data receive");
}
totalreceive += _lastReceive;
} while (totalreceive < length);
}
return buffer;
}
what is my problem ? I don't want to use sync calls because the rest of the
session is async also , so I only want to makethe async - sinc like forthis
part ofthe code , also , when in the debug mode I change the
OpenSocket.Blocking to True - cause it to call sync receive instead of
beginrecv , also return with zero length buffer
any ideas ?
.
- Follow-Ups:
- Prev by Date: Embedded text fields in Crystal Report
- Next by Date: Re: day-difference between 2 datetimes
- Previous by thread: Embedded text fields in Crystal Report
- Next by thread: Re: BeginReceive return zero length buffer when run ,and work correctly when use step by step debug mode
- Index(es):
Relevant Pages
|
Loading