Re: Sockets Beginreceive not working correctly.
- From: "David" <someone@xxxxxx>
- Date: Tue, 20 Jan 2009 20:33:30 -0600
I'm only sending the word "hello", the first time I step through the code, I
recieve the data, the second time, I don't. It seems like the line that has
the beginrecieve is ignored.
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.un2w69s08jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Tue, 20 Jan 2009 15:19:16 -0800, David <nospam@xxxxxxxx> wrote:
I'm using Sockets to send a receive data. My issue is when I open up a
socket, I can send and receive data correctly the first try. Upon the
second try without closing anything, I send some data, but receive
nothing.
There are two likely possibilities:
-- By the time you get to stepping through the code, all of the data
you sent has been sent. In which case, it will all have been received by
your first receive (assuming the buffer's big enough).
-- By the time you get to stepping through the code, the second part
of your data hasn't yet been sent.
In either case, there's no reason to expect your callback method to be
executed.
I noticed as I step through the code, during the second receive, I
execute
the client.BeginReceive but the debugger goes to the next line without
going
into the callback function, as if that Client.BeginRecieve line isn't
there.
No errors occur.
BeginReceive() would not normally execute the callback in any case. The
normal use case involves BeginReceive() returning immediately, and your
callback being executed at some later time, when there's actually data to
be received.
Anyone have any ideas, what that maybe. Would I have some something
blocking
from the first receive?
Without a concise-but-complete code sample, it's impossible to say for
sure why your expectations are incorrect. However, suffice to say that
the likelihood of it actually being the case that "Beginreceive [sic] not
working correctly" is practically non-existent. You are surely doing
something wrong.
By the way, one thing I can see from your code that you're definitely
doing wrong is using a new Encoding instance each time you receive more
data. You should be calling GetDecoder() and using the one Decoder you
get each time you receive bytes, so that it can correctly deal with
multi-byte characters that might have gotten split up during transmission.
Pete
.
- Follow-Ups:
- Re: Sockets Beginreceive not working correctly.
- From: Peter Duniho
- Re: Sockets Beginreceive not working correctly.
- From: Michael D. Ober
- Re: Sockets Beginreceive not working correctly.
- References:
- Sockets Beginreceive not working correctly.
- From: David
- Re: Sockets Beginreceive not working correctly.
- From: Peter Duniho
- Sockets Beginreceive not working correctly.
- Prev by Date: Re: Handling Process Input and Output Streams
- Next by Date: Re: Can't find System.Runtime.InteropServices
- Previous by thread: Re: Sockets Beginreceive not working correctly.
- Next by thread: Re: Sockets Beginreceive not working correctly.
- Index(es):
Relevant Pages
|