Jump to content

Simple UDP client/server program

- - - - -

  • Please log in to reply
2 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
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

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

-Michael Sinz

#2
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
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.
Latinamne loqueris?

#3
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
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).
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users