473,396 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

TCP Delivery

Airslash
221 100+
Hello,

I hope this is the correct forum to ask this...

I'm working on a client-server architecture application that relies on the TCP/IP protocol for transmitting data between the client and server application.

I've made my own protocol for the application that relies on the following structure:
@VT: <type> <size> [binary block]#

- Each message starts with @VT:
- type is an integer, identifying the type
- size is the length of the binary block
- binary block contains type specific data
- each message ends with #

Currently we're having discussions here whether or not to fully parse incoming data. Since I'm working with TCP, I assume that when I receive data on the incoming socket (C#.NET Sockets), the data contained in the socket is a complete message, meaning it starts with @VT: and ends with #.

Colleagues of mine say I need to parse the buffer everytime to search for an @ symbol and then parse the remaining data.

who is right?
Sep 10 '10 #1

✓ answered by sicarie

Ah, yes, it's entirely possible - TCP negotiates packet size during the handshake, it is possible the agreed upon size is less than the largest 'packet' from your protocol.

7 2556
sicarie
4,677 Expert Mod 4TB
I'm not sure I completely understand you, but if you've created a protocol within TCP, you should be able to use the tools within TCP to verify if the message is complete or not.

Inside that, you should parse your own protocol for completion anyway - just as a method of error-checking. There are plugins and toolbars that allow you to inject into packets, so input validation is key.

That's just a personal opinion, though - if you have error checking on your client sending info, it's your decision if you want to parse it on the server end.
Sep 14 '10 #2
Airslash
221 100+
What I'm trying to say is that we had a discussion about the TCP itself.

I assume that when TCP reports that data is available on the socket, that I have a complete message available. My colleague says that It is possible that I only have a part of the message on the socket and that I always need to validate the whole content.

I've had occurances of 2 messages beeing in the socket, but havent encountered the issue that I only had a partial message.
Sep 15 '10 #3
sicarie
4,677 Expert Mod 4TB
Ah, yes, it's entirely possible - TCP negotiates packet size during the handshake, it is possible the agreed upon size is less than the largest 'packet' from your protocol.
Sep 15 '10 #4
Banfa
9,065 Expert Mod 8TB
Sorry to step in late I just want to reinforce what sicarie has said since he is right.

There are 2 normal protocols to use across an enternet, TCP and UDP.

TCP is a connection based byte stream. That is you open a connection and only transmit once you know the connection is open. When you transmit what you transmit is a stream of bytes, that is the tcp stack has no concept of sending messages, it sends data, a minimum of 1 byte and a maximum normally defined by the underlying link layer (a little bit over 1400 bytes on most wire and wireless networks but depends on medium, you often get smaller MTUs on mobile phone networks). TCP also guarantees that if you receive the data it will be correct and in the right order.

The important point here is that it is a byte stream not message orientated, that means the TCP stack may split the data it has anyway it chooses without regard for what you term message boundaries. You might receive bits of a message at a time or several messages all together.

When handling a TCP connection you need to account for this by treating the data as what it is, a byte stream, so your program should be capable of handling data reception a byte at a time and should make no assumptions about what it has received (i.e. having received the message header/size assuming the rest of the data is either available or lost, it just may not have turned up yet).

By contrast UDP is connection less and message based. You do not have to set-up a connection, you transmit the message in a fire and forget manner, that is sending end does not concern itself with worrying about if the data arrived. The delivery is not guaranteed although UDP can (but is not required to) use a checksum in which case you can normally rely on the message being correct if it does arrive. Also UDP makes no guarantee about order of deliver, that is a message sent 2nd may arrive 1st.

Data only arrives if the receiving computer was looking for a message at the time it arrives. Also because UDP sends its data as messages it is desirable where possible to limit the message length to the UDP message so it fits into length of the link layer with the smallest MTU on the route. This prevent fragmentation of the message and that is good because once fragmented only 1 of the fragments needs to be lost to loose the whole message, since there is no re-transmit.

When UDP data arrives it is a whole and single message and the UDP header carries the size of that message. So if you receive a UDP packet you can expect it to be a complete and whole message.
Sep 27 '10 #5
Airslash
221 100+
I finally got around to implementing a nice system around my socket.

Currently it works like this:

- TCP Berkley socket listens for incoming data.
- When data arrives, the socket reads it and write it at the back of a memory buffer.
- A parser uses a background thread to loop over the buffer from the start and analyses the data, seeking the start & end of a message according my protocol
- If the parser finds a message, it removes that data from the buffer and raises an event, then seeks the next message.

Currently working like a charm, still ironing out several bugs about odd situations that can occur, but the general application flow seems to work fine.

Thanks for the explanations. I've taken Sicarie's reply as he/she was first with the explanation (Sorry Banfa :))
Sep 27 '10 #6
Banfa
9,065 Expert Mod 8TB
That's OK its not a competition :D

Sounds workable, since you are accessing the buffer from 2 separate threads I assume your using some synchronisation object (a semaphore) to protect the buffer access?
Sep 27 '10 #7
Airslash
221 100+
Yup,

I have written a class called MemoryBuffer that wraps an IList<byte> object and protects it with a lock for exclusive access through every public method.
Sep 27 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: postmaster | last post by:
This is an automatically generated Delivery Failure Notification. Delivery to the recipient failed. Status Code: 5.1.1 User Unknown If you are trying to reach Blue, please send email to...
0
by: postmaster | last post by:
This is an automatically generated Delivery Status Notification. Delivery to the following recipients failed. LPOLLARD@Darbylaw.com
3
by: Cliff Wells | last post by:
From: zonk@azet.sk To: Cliff Wells <clifford.wells@comcast.net> Subject: Sprava nebola dorucena (Message was not delivered) Date: 13 Oct 2004 15:26:00 -0000 (08:26
0
by: Mail Delivery Service | last post by:
This multi-part MIME message contains a Delivery Status Notification. If you can see this text, your mail client may not be able to understand MIME formatted messages or DSNs (see RFC 2045 through...
1
by: OC | last post by:
Does anyone know if there is any support for guaranteed delivery of messages such as with MSMQ for .NET (webservices, etc.)? I have a high-speed data-entry application being ported from the...
0
by: Dica | last post by:
i think i've gotten the wrong idea about the differences between a read receipt and delivery status notificaiton. i was assuming that delivery status notificaiton is a response line from the remote...
5
by: Chris Thunell | last post by:
I'm using the system.web.mail in vb.net to send emails out in a vb.net application. The sending of emails works great. Is there a way to have it send me back a delivery receipt or a read receipt?...
0
by: Kostadin Kostov | last post by:
Hi! I'm developing component for sending emails and want to have the ability to request delivery receipt when sending an email. I use the "Return-Receipt-To" header:...
2
by: audiophilechris | last post by:
Can anyway help me write this query? I've created a DB to help me manage delivery logistics for items I rent out. I have a table that i use to record delivery date, delivery time, pickup date,...
0
by: Michael Bell | last post by:
From: Mail Delivery System <Mailer-Daemon@ptb-relay02.plus.net> To: michael@beaverbell.co.uk Subject: Mail delivery failure: returning message to sender Date: Wed, 31 Oct 2007 19:39:57 +0000 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...

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.