474,099 Members | 1,779 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 784

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

Similar topics

4
1851
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
1235
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
7612
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
16714
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
3833
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...
5
11779
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
6
13188
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
977
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
2008
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
7036
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
10665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
12335
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...
1
12327
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
11246
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...
0
10461
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6847
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
5569
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
5059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
4135
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.