473,847 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Receive/EndReceive with message spanning multiple calls

I'm creating a system wide (distributed) Publish/Subscribe Event Broker using
..NET Sockets as the transport mechanism. I'm doing all my
connects/accepts/sends/receives
asynchronously (well, not all, but thats beside the point really). I also
have an EventBroker that all clients connect to and the EventBroker holds the
open socket connections to communicate with. My problem is, how do I know
when my EndReceive call has finished a message? Doing 'if bytesRead > 0'
doesn't work because I'm not closing my connections. Is the only way to look
for some sort of EndOfMessage tag?
ie.
bytesRead = EndReceive(ar)
if bytesRead > 0 then
append message to some buffer
if message has EOM tag
signal complete message received
endif
beginReceive
else
server dropped connection/process error condition
endif

I don't mind coding for that if thats the only way, I just want confirmation
from someone. Also, in my message that has the EOM tag, will that message
stop there? That is, is it possible to have a message fragment that looks
like:
[...message XX<EOM>Message YY]
where a packet contains the end of one message and the beginning of another
message? Do I need to code for that situation?

Any help is greatly appreciated.
Ken

Nov 21 '05 #1
0 969

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

Similar topics

4
1845
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, SocketState.BufferSize, 0, new AsyncCallback(this.ReadCallback), sockState); The ReadCallback() method begins:
0
1219
by: Pete Davis | last post by:
I'm trying to do async socket IO in a socket server in C# and I'm having trouble on the receive side of things. I've tried variations of the code below and I just can't seem to get it to work. I think my _receiveEvent.Set() calls may be misplaced among other things. EndReceive() gets called when the first message is sent. What I want it to do is to continue to receive until the entire message has arrived. I'm not really sure how to...
4
7597
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 EndReceive calls... these calls seem to be sometimes coming out of order. For example, the following is from my log file: Connection at 5/1/2004 11:39:14 AM SENT> ZZZ:1:FMZZZ:ID1234:PWAAAA:VR100:\0 RCVD>...
6
16684
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 returns true at this point, which I know is expected behavior, so when I reach this state, I begin sending on this socket every few seconds until an error is generated. After the exception is raised, Socket.Connected returns false.
4
3797
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 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...
6
13159
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 the socket.EndReceive method called in the 2nd thread receives some data from the socket. If the 1st thread will block until the 2nd thread receives some data from the socket, what is the point of starting up the 2nd thread? I am aware I can...
0
775
by: Ken Foster | last post by:
I'm creating a system wide (distributed) Publish/Subscribe Event Broker using ..NET Sockets as the transport mechanism. I'm doing all my connects/accepts/sends/receives asynchronously (well, not all, but thats beside the point really). I also have an EventBroker that all clients connect to and the EventBroker holds the open socket connections to communicate with. My problem is, how do I know when my EndReceive call has finished a message?...
1
1996
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 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...
6
7011
by: Pat B | last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol using C#. I have implemented it using BeginReceive and EndReceive calls so as not to block when waiting for data from the supernode. Everything I have written works fine sending and receiving uncompressed data. But now I want to implement compression using the deflate algorithm as the Gnutella protocol accepts: Accept-Encoding: deflate Content-Encoding: deflate in the...
0
10987
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10652
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10709
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10343
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7885
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7058
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5723
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4535
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 we have to send another system
2
4125
muto222
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.