473,473 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Socket issues with EndReceive

I have a Socket based application using the asynchronous Sends and Receives
of the Socket class. I send out XML strings using BeginSend/EndSend from a
client end point, the server side does a BeginReceive/EndReceive.

I knew a message could be split up between Receives and I look for an end of
message marker (and continue receiving if not there) before processing the
complete message. However I was told (on this board I think) that I would not
have to deal with multiple messages in one packet. That is, I wouldn't get
[Message1]<EOM>[Message2] in the same Receive Buffer.

But that is exactly what I'm seeing. I can code for this if thats to be
expected, but I wanted to know if this is a sign of a bug, or this is really
what should/could happen with asynchronous Sockets.

Should I assume that a Receive on a given socket from a given RemoteEndpoint
is not separate and distinct messages but a continuous message stream where
one message could be broken up across multiple packets AND multiple messages
(or parts of messages) may show up in one packet?

Thanks,
Ken
Nov 16 '05 #1
4 3758
Yep, it is a stream and not a bug.
Nov 16 '05 #2
Okay, so within one socket channel (a fixed localEndPoint/remoteEndPoint)
multiple sends could show up back to back in the same receive buffer? Good to
know, I'll code for that.

Is this just for one socket connection though? I have one listening Port on
a server that several clients connect to. Each client connection gets its own
BeginReceive call. They won't overlap right? The messages could be connected
together in a single stream, BUT ONLY if those messages originated from the
same client end point?

Sorry if that seems overly nitpicking, but i've heard conflicting answers
and just wanted to make sure I have the facts straight.
"Joep" wrote:
Yep, it is a stream and not a bug.

Nov 16 '05 #3
> Okay, so within one socket channel (a fixed localEndPoint/remoteEndPoint)
multiple sends could show up back to back in the same receive buffer? Good to know, I'll code for that.
yes. When you read the stream you could get 1 byte or more, there are no
message boundaries like udp. You define your own message boundaries with
tcp stream. Also note I have yet to confirm this myself, but have heard a
report from someone that sounded credible that Async Send may not send all
bytes as the doco says for connection-oriented socket, so you should check
for that as well. Also, with Async socket calls, you can get the callback
for send2 before the callback for send1, which "may" effect you dramatically
depending on your logic.

Is this just for one socket connection though?


Yes as each client has own socket on your listener side so they the streams
don't effect each other.

--
William Stacey, MVP
Nov 16 '05 #4
Good to know about the possible break up of a send, that should be simple
enough to code for defensively.

Could you elaborate on what you mean about send2 before send1? Do you mean
the message sent from send 2 will (in its entirety even if across multiple
receives) arrive before the message from send1? If thats the case we're okay,
we have synchronous and asynchronous sends, the developers are instructed on
when to use one vs. the other, if timing is an issue, synchronous is to be
used.

But if you mean a message stream may arrive mixed up, that is a bigger issue.
"William Stacey [MVP]" wrote:
Okay, so within one socket channel (a fixed localEndPoint/remoteEndPoint)
multiple sends could show up back to back in the same receive buffer? Good

to
know, I'll code for that.


yes. When you read the stream you could get 1 byte or more, there are no
message boundaries like udp. You define your own message boundaries with
tcp stream. Also note I have yet to confirm this myself, but have heard a
report from someone that sounded credible that Async Send may not send all
bytes as the doco says for connection-oriented socket, so you should check
for that as well. Also, with Async socket calls, you can get the callback
for send2 before the callback for send1, which "may" effect you dramatically
depending on your logic.

Is this just for one socket connection though?


Yes as each client has own socket on your listener side so they the streams
don't effect each other.

--
William Stacey, MVP

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pete Davis | last post by:
I've written an async socket server app and I'm having an issue with the EndReceive() call. My begin receive call is: sockState.RemoteSocket.BeginReceive(sockState.ReceiveBuffer, 0,...
4
by: Brian Rice | last post by:
I have a socket application that is sending and receiving packets asynchronously. It works great except, when I receive packets that are larger than my receive buffer which then generate several...
6
by: Bruce Vander Werf | last post by:
I am using the asynchronous send/receive methods of the Socket class. When the remote end closes the socket, the callback for receive is called and EndReceive returns 0. Socket.Connected still...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
1
by: Andre | last post by:
Hi, I'm implementing an asynchron socket Receiving method and I have a question about EndReceive. Read() { Socket.BeginReceive(buf,0,buf.Length,0,new AsyncCallback(ReadCallback),dp); }
6
by: Steve Richter | last post by:
I dont get the point of socket.BeginReceive and socket.EndReceive. As I understand it, BeginReceive will start a 2nd thread, call the ReceiveCallback delegate in the 2nd thread, then block until...
1
by: Ken Foster | last post by:
I have a Socket based application using the asynchronous Sends and Receives of the Socket class. I send out XML strings using BeginSend/EndSend from a client end point, the server side does a...
8
by: Dinsdale | last post by:
I am trying to write a Tcp "Server" that opens a class that wraps a tcp socket when a new connection is made (Listener.AcceptSocket()). Everything is going swimmingly except when I try to close the...
2
by: O.B. | last post by:
I have a C# Socket configured for streaming TCP. Upon making a valid connection, I have an asynchronous callback configured using BeginReceive. Within the BeginReceive declaration, I set the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.