Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Simple UDP client/server program


  • Please log in to reply
2 replies to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 12 December 2011 - 12:52 PM

Hello,

I'm trying to create a simple client/server program using UDP on C. I achieved to connect the client with the server and send and recover the data. My question now is how to disconnect the client from server and how server will wait and handle the closing of the connection? I have two methods, Disconnect() on client and Close() on server. In addition, I have a standard output path that need to follow. For example at the beginning need to have :

[Server] - Waiting for connection...[Client] - Opening connection OK

I don't have this result all the time, basically have random place. For example

[Client] - Opening connection [Server] - Waiting for connection...OK

How can I handle this too?

Thanks in advance,
toto_7
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2 mebob

mebob

    CC Devotee

  • Validating
  • PipPipPipPipPipPip
  • 467 posts
  • Programming Language:C, C++, Assembly
  • Learning:PHP

Posted 16 December 2011 - 04:25 PM

UDP, unlike TCP, has no concept of a server or client, only a sender and a receiver for each packet. There is no concept of a connection, so there is nothing to disconnect. You would simply close the handle using the sockets functions.
  • 0
Latinamne loqueris?

#3 Flying Dutchman

Flying Dutchman

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1090 posts
  • Location:::1
  • Programming Language:C++, Python

Posted 17 December 2011 - 12:15 AM

UDP is: send data, which is not guaranteed to arrive, or to even arrive in correct order at other end point. Since it has very little overhead, it's useful where you need to "update" information very quickly, but don't really care about accuracy (packet loss). It's mostly used in FPS games (that's why you sometimes see a player "teleporting" on the map).
  • 0

The roots of education are bitter, but the fruit is sweet.





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download