BeginReceive return zero length buffer when run ,and work correctly when use step by step debug mode



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 ?


.



Relevant Pages

  • Re: Strange C error
    ... Getting debug output back via wimp error boxes sounds a bit painful! ... is the length of the icon's buffer? ... variables in a function with gcc? ...
    (comp.sys.acorn.programmer)
  • Re: BeginReceive return zero length buffer when run ,and work correctly when use step by step debug
    ... when I debug step by step the both sides, ... also the buffer is empty. ... int length) ... so I only want to makethe async - sinc like ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: cxx0017: ... symbol not found VC++6
    ... You are running a debug build of the project with debug symbols ... // At this point should be pointing at workingBuf at the point of the ... // buffer end is reached before a $ is found the device should be ... // First check for end of buffer and read input buffer (newBuf) if ...
    (microsoft.public.vc.language)
  • Re: waveINxxx "bad pointer" error in Debug version
    ... This seems to indicate something with the debug rt library causing the ... preparing the buffers once, receiving full buffers for MM_WIM_DATA and ... The pointer pwaveHdr1 is in your data section so if the pointer ... _wctime_s needs a buffer of 26 characters. ...
    (microsoft.public.win32.programmer.mmedia)
  • LoadUserProfile() returns ERROR_ACCESS_DENIED
    ... GetLastError() returns 5 ... debug(buffer); ... debug("Couldn't set 'SE_ASSIGNPRIMARYTOKEN_NAME' privilege for this ...
    (microsoft.public.platformsdk.security)

Loading