Re: 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 19:35:02 +0200
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 ?
.
- Follow-Ups:
- References:
- Prev by Date: How does one check if an object's reference is NULL?
- Next by Date: Re: How does one check if an object's reference is NULL?
- Previous by thread: Re: BeginReceive return zero length buffer when run ,and work correctly when use step by step debug mode
- 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