UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-11-18 09:00 PM

sangfroid
Member
Registered: 2006-09-18
Posts: 29

Re: byte stream and datagrams

Hi,
What is the difference between byte stream protocol and datagram protocol? What do they infact mean and get implemented.. Please simply dont say that TCP is byte stream and UDP is a datagram protocol. I am not getting what is the core difference in these ? ( not the difference between working of tcp and upd )

Thank you

Offline

#2 2006-11-19 01:34 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,234

Re: byte stream and datagrams

A byte stream consist of one big chunk of data with no segments or other irregularities. With datagrams (smaller) data chunks are send and received at once as a whole.

In practice it means that with datagrams each send/write call sends one packet, and each read/recv call receives one packet, while with stream protocol the data can be send and received in any way. E.g. A sender can call send() ten times, while the receiver receives all that data with one recv call. With datagrams ten send calls means ten packets and ten receive calls.

Offline

#3 2006-11-19 11:56 AM

sangfroid
Member
Registered: 2006-09-18
Posts: 29

Re: byte stream and datagrams

Has it something to do with buffering at sender's /receiver's end ? Like sender buffers until it gets data with total size of MSS and receiver reads chunk of data at a time and so on ??


i3839 wrote:

A byte stream consist of one big chunk of data with no segments or other irregularities. With datagrams (smaller) data chunks are send and received at once as a whole.

In practice it means that with datagrams each send/write call sends one packet, and each read/recv call receives one packet, while with stream protocol the data can be send and received in any way. E.g. A sender can call send() ten times, while the receiver receives all that data with one recv call. With datagrams ten send calls means ten packets and ten receive calls.

Offline

#4 2006-11-19 02:29 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,234

Re: byte stream and datagrams

Yes, with stream based protocols the network stack is free how to do the buffering, with datagrams it's forced to buffer per packet. Streams don't have a notion of packets, recv() and send() only push or get a part of the stream.

Offline

#5 2006-11-19 09:04 PM

sangfroid
Member
Registered: 2006-09-18
Posts: 29

Re: byte stream and datagrams

is it possible to explain a bit more with some examples...any arbitary example will do...
i am a bit confused what stream based protocol really is....


i3839 wrote:

Yes, with stream based protocols the network stack is free how to do the buffering, with datagrams it's forced to buffer per packet. Streams don't have a notion of packets, recv() and send() only push or get a part of the stream.

Offline

#6 2006-11-19 11:36 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,234

Re: byte stream and datagrams

Any example, huh? Watch out what you ask for. ;-)

Let's compare it with bringing water from one place to the other.

A datagram protocol is comparable with moving water around by buckets. The sender brings a bucket and the receiver either takes it or not.

A streaming protocol can be compared to a big container with a tube at the bottom. The sender throws in water at the top, and the receiver gets it from the tube.

Similar, rain uses a datagrams protocol while a river uses a streaming protocol.

Of course this are a bad examples, e.g. in reality the bytes will be ordened, while water isn't really. If you want another arbitrary example, ask. ;-)

Offline

#7 2006-11-20 06:27 AM

sangfroid
Member
Registered: 2006-09-18
Posts: 29

Re: byte stream and datagrams

haha no more....

i3839 wrote:

Any example, huh? Watch out what you ask for. ;-)

Let's compare it with bringing water from one place to the other.

A datagram protocol is comparable with moving water around by buckets. The sender brings a bucket and the receiver either takes it or not.

A streaming protocol can be compared to a big container with a tube at the bottom. The sender throws in water at the top, and the receiver gets it from the tube.

Similar, rain uses a datagrams protocol while a river uses a streaming protocol.

Of course this are a bad examples, e.g. in reality the bytes will be ordened, while water isn't really. If you want another arbitrary example, ask. ;-)

Offline

#8 2014-12-18 09:42 PM

Hemanth kumar N
Guest

Re: byte stream and datagrams

Good example

Board footer

Powered by FluxBB