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



No,
I have some send recv conversation between 2 clients
the mode is async sockets.
when I come to some location in the code that I want to recv 5 bytes , the
recv return before the bytes received , the length of the EndRecv() is 0
(zero) ,
I use the async result of the BeginReceive() WaitHandle.WaitOne() to block
on this thread until the bytes come , but , it does not block and return as
I described above.
When I debug this process of the both clients STEP by STEP , it's work
correctly and return those 5 bytes !
so , I can't find whay it's happen !
"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message
news:ubJcZqL2GHA.4264@xxxxxxxxxxxxxxxxxxxxxxx
Bit confused by what you are saying is the problem but can you calrify.

If you send an object to the other client, it is not always getting there.
But if you debug, it does? Is the problem that you are 'losing' bytes?


"semedao" <semedao@xxxxxxxxxxxxxxxx> wrote in message
news:eiYtLmL2GHA.1588@xxxxxxxxxxxxxxxxxxxxxxx
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

  • Help Needed: One "recv()" contains data sent by many "send()" ...
    ... It recvand send data between clients. ... example, On executing recv() with a buffer of size> 512 bytes, the buffer ... My concern is this Incomplete message, ...
    (microsoft.public.windows.server.networking)
  • Re: Sockets and Buffer size
    ... For 10 clients, I would not even use async but a thread per client server ... far as buffer size. ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with popen
    ... Under linux x86 I'm running a stress test which opens some tcp server ... applications and then about 70 clients in each their thread. ... The server however is started as an async process using fork and then ... sync and async processes. ...
    (comp.unix.programmer)
  • Re: Good websites for Custom Components
    ... If we didn't want everything popping out the bottom of the component that came in at the top we would have to be async. ... A sync component simply puts everything it saw coming in, out, no change of buffer. ... So it might be a viable approach to check uniqueness in either an SSIS ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: bluetooth driver
    ... I open the connection to the device by using CreateFile method with "Async" ... "The supplied user buffer is not valid for the requested operation" ... Insert any Bluetooth dongle USB ... Reinstall the driver to the driver attached with this email ...
    (microsoft.public.development.device.drivers)

Loading