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

You are not logged in.

#1 2019-03-28 07:33 AM

Registered: 2019-03-28
Posts: 1

STREAM and Datagram Socket what to choose....

Hello everyone,,
I am develop a client/server application.
First my client has to obtain a list of variable length names from the server.
Then my  Sarkari Result Pnr Status Showbox client will query  for changes of numeric values associated with name periodically.
I have 10,000 names and each name is about 200 bytes. Total is about 2 MB.
I have about maximum 60 K of numeric values.  Normally, I have about 10 K of changes on average to send from server to client.

I am not sure what is the most appropriate : connection and connectionless?
If connection, should I limit the size of the packet.

Any idea. Or example that is similar to my case here?

Last edited by Kidbooo (2019-03-30 05:16 PM)


#2 2019-03-28 02:39 PM

From: Boston, MA
Registered: 2002-06-12
Posts: 3,844

Re: STREAM and Datagram Socket what to choose....

The most important thing to consider is: are your messages important and need to arrive or can you stand to lose some and not cause any major problems?  If they're important, you probably want TCP (ie: connection-based SOCK_STREAM)...  If you can stand to lose a few now and then, you might be better off with UDP (ie: connectionless SOCK_DGRAM)...  There are other considerations, but I think that's the most fundamental one to think about...  There are times where you can effectively rewrite your own TCP reliability handling on top of a UDP socket if you have to when UDP is a better overall fit otherwise, but I wouldn't recommend it if you can avoid it...  If you need reliability, your best bet is generally going to be TCP...

I'm not sure what you mean by your question "should I limit the size of the packet"...  With TCP, from an app level, you generally don't care about the packets, as you're just working with a data stream...  You send as much or as little as you want down the stream, and TCP figures out how to divide it up as packets...  Unless by "packets" you meant app-level messages?  For those, just pick sizes that make sense for the data you're transfering...  You'll probably need to pick an appropriate scheme for sending and receiving the messages; either delimited messages or a fixed-length size header followed by the variable-length data...  Because, remember, it's just a data stream, not a packet-based socket like UDP...


Board footer

Powered by FluxBB