• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

creating and sending and recieving UDP packets

Hello all,

I am having real trouble writing a basic client/server program in C that passes UDP packets and wonder if someone could please help?

I fully understand how to get the client to send a string to the listening server (this part already works) but my question is how can I impliment the following?

   I need to make and send with each packet a udp packet header (struct) that holds a sequence number and a flag to mark the start and end.

   I need to delcare a packet payload size (say 10 bytes) and split whatever file is passed, into packets of this size and send them to the server.

   I need to display the number of packets passed to server (on the server) and check for out of sequence packets

The connection need only be one way. I guess this is like a simulation of  tcp (without acknowledgement). Unfortuantly I can not use TCP.

I hope someone is an experienced socket programmer or alike!!

This is killing me :(

Thanks

Ren
0
Beam
Asked:
Beam
  • 3
  • 3
  • 2
  • +2
1 Solution
 
PaulCaswellCommented:
This might be from one of your fellow students:

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21378237.html

We cannot do your coursework for you. Please make a reasonable effort and post your code. We can then help much more.

Paul
0
 
BeamAuthor Commented:
It might well be?

But the basis of my question is very different.

I am sorry if it came across like the other question (please write me client/ server software from the start!!) that is certainly not the not the case here. I like the bit when he/she siad 'I had function like that but called a different name!!' hmmmm!

Basically I fully understand binding to the socket and sending data and then recieving it on the server end. I can write a packet header (just a simple struct), but the problem I am having is spliting the data passed in. I passed in the localhost (agrc) and the data agrv[2].  (agrv[] is char array)

Now I need to split that into to payloads (say 10 bytes) and send them to the server.

So I want to :

take the 10 bytes at a time from agrv[2] and send them. When I get to the last packet I want to send what ever size that is.

The rest of the question is not such a problem.

If you want any code samples I can post :)

Sorry for starting on the wrong foot :)

Ren





0
 
PaulCaswellCommented:
Ren,

Take a look at my first response to Phil. I am doing almost exactly what you are asking, even, by coincidence, taking 10 bytes at a time.

Paul
0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
Kent OlsenData Warehouse Architect / DBACommented:

Hi Ren,

Whenever someone posts a question about writing a client/server application using UDP I instinctively ask "Why?"

UDP is kind of a special purpose protocol that is not applicable for most applications.  If you need to know that the data arrived at the other end or that the packets arrived in the order sent (i.e. your data is intact) then you'll need to use TCP.  Most of the programming and interface is the same, but there are few subtle differences.


Kent
0
 
grg99Commented:
It's your typical make-work kind of assignment.  I hope the teacher also mentions that "see how hard it is to do this?  Plus , your code probably performs poorly on a congested network.  Use TCP, it handles all that hard stuff"

Basically what the poor guy has to do is define a struct:  { int BytesInThisPacket; int SequenceNumber; char Body[10000] };

Then move the data into Body, set the fields, do a udpwrite of the correct length, then do the opposite on the other end.


0
 
Kent OlsenData Warehouse Architect / DBACommented:

Hi grg99,

Yeah.  We see a lot of these kinds of questions.  It's disappointing how few of them even understand the difference between UDP and TCP.


Kent
0
 
stefan73Commented:
Hi Kdo,

Yes, you're right. It's also annoying to see the very same question again and again (like the currency converter).

Stefan
0
 
BeamAuthor Commented:
Ok, firstly sorry to bore you Stefan with the 'same question'.

Secondly, In the future Kent you should read the questions a little more carefully. I fully understand the difference between the unreliable UDP and the reliable( but with higher overhead) TCP procotol. I fully understand where they fit into to the OSI layers. I understand issues such as lack of acknowledge and in what situation they should be used etc etc etc.

Maybe Kent should think about why someone would want to try and simulate a  reliable(ish!!) UDP packet instead of just suggesting the 'soft options'. People who ask questions often have a reason after all!!!!! In this case it was for acdemic reasons, to fully understand the how to pass datagrams and construct packets of this type.

Thanks Paul for the push in the right direction. I have now constructed my client/server programs and met the specification.

:) Ren
0
 
stefan73Commented:
Hi Ren!

Sorry - it's just that this question is a déjà vu...
Sure, there are uses for UDP. They're rare, most people just need a data stream. And UDP packages are not guaranteed to arrive in the same order as you sent them. UDP is helpful when you have a stateless protocol (isn't that a contradiction in itself?).

For example, you could have a machine which is a sophisticated random generator. It could send its output by UDP, as it doesn't matter in which order the packages arrive.

Stefan
0
 
PaulCaswellCommented:
Kent/Stefan,

I totally agree with you. It deeply saddens me to meet people who cannot think beyond that which they already know and therefore end up repeating the same mistakes. The deepest core of this problem, I believe, is our current inability to encode knowledge in a truly portable and available fashion. In the age of the computer and fabulous graphics systems that can generate incredibly realistic moving images at a cost within the price range of a child, how come we still code in text?

Ren,

I appreciate the thanks.

A word, however, might be appropriate here. Kent is an intelligent, wise and deeply knowledgable person who has helped many on this board. I think you may have misinterpreted his words. It may be worthwhile re-reading his comments in this light to be sure that he deserved the remarks you made.

Paul
0
 
BeamAuthor Commented:
I guess you are right Paul, I meant no offence to Kent. It is just do not like it when people pigeon hole you. I am sure most of the people who post this sort of question understand the difference between UDP and TCP, its only takes a  basic level of intelligence!!

What they dont understand maybe (like me in this case) is the c syntax!!! and this is where you guys come in :)

Sorry to stir up any bad feeling.

Take it easy (including Kent) and thanks again.

Ren :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

IT Degree with Certifications Included

Aspire to become a network administrator, network security analyst, or computer and information systems manager? Make the most of your experience as an IT professional by earning your B.S. in Network Operations and Security.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now