Need help in UDP "connection" Topic is solved
-
- Knows some wx things
- Posts: 31
- Joined: Wed May 24, 2006 12:45 am
- Contact:
Need help in UDP "connection"
As UDP don't have a reliable connection, how can I detect a client is disconnected(due to the client application crashed, power cut, cable unpluged) on server side?
any suggestion would be appreciated.
any suggestion would be appreciated.
Re: Need help in UDP "connection"
You can't.liangbowen wrote:As UDP don't have a reliable connection, how can I detect a client is disconnected(due to the client application crashed, power cut, cable unpluged) on server side?
One simlpe thing to do would be to have a ping <-> pong scheme, where the clients acknowldege packets. Apart from that you could have a TCP socket connection that simply does nothing but hanging around until one of the client disconnects.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
-
- Knows some wx things
- Posts: 31
- Joined: Wed May 24, 2006 12:45 am
- Contact:
Hmm..liangbowen wrote:If I use the "a ping <-> pong scheme"(is this also called keep-alive?), how long shall the interval be reasonable?
someone suggested me to make the clients send keep alive messages to server every 1 sec. but will that cause a network congestion if the server has several thousand clients connecting?
This is not a true keep-alive. keep-alive would mean something like when you have a TCP connection that would be closed by the server after a timeout limit, you send a special message to generate some traffic to leave the connection open.
As UDP is connection-less, there is no "true" keep alive. UDP is fire-and-forget.
What I meant was checking if requests where actualy processed. It's a resquest <-> acknowledge scheme. Like when you send a packet, the server would send a small acknowledge message back, tellling you the it got the packet.
It mainly depends on what you want to achieve. Sending packets every second to thousands of clients is not a good idea. What I did once for a small VoIP app was two approaches:
1. Have a TCP and UDP socket.
2. Use an acknowledgement scheme.
1. The TCP socket was used for not traffic, but to get the connection status. If it was closed or destroyed, so was the UDP socket.
2. Every packet had an ID number and for every 100th packet the client send an acknowledge packet back.
In my case the order of packets and packet loss wasn't important. That's why UDP made perfect sense. If you really need to have an established connection and need to be able to check that everytime, maybe consider using TCP socket.
What do you want to do?
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
-
- Knows some wx things
- Posts: 31
- Joined: Wed May 24, 2006 12:45 am
- Contact:
I am writing a p2p program, sometimes client program failed to send packet to server or failed to receive packet from server. If this packet is about command like "get users list", I can perform an ACK on server side and client side.
But if a command like "logout", ACK may not work, because clients just don't click the "LogOut" button, they click the exit program button([x]) directly, I can send a "log out" message to server right before the program distroy, but not likely to perform an ACK.
And what if the client program crashed? Especially when it's a client note takes an important role.
I'm thinking to perform a "check clients alive" scheme on serverside to check if the clients is alive. but that means the server have to send "check alive" packets to all clients for every x seconds. How long would the x be reasonable?
And still I don't think it's a good idea. Because what if the clients don't get the "check alive" message becuase of the temporary bad network congestion in serveral seconds or becuase the client's nat session changed? And when it comes back(say send a "list users" message to server) just to found itself has been kicked out from server.
But if a command like "logout", ACK may not work, because clients just don't click the "LogOut" button, they click the exit program button([x]) directly, I can send a "log out" message to server right before the program distroy, but not likely to perform an ACK.
And what if the client program crashed? Especially when it's a client note takes an important role.
I'm thinking to perform a "check clients alive" scheme on serverside to check if the clients is alive. but that means the server have to send "check alive" packets to all clients for every x seconds. How long would the x be reasonable?
And still I don't think it's a good idea. Because what if the clients don't get the "check alive" message becuase of the temporary bad network congestion in serveral seconds or becuase the client's nat session changed? And when it comes back(say send a "list users" message to server) just to found itself has been kicked out from server.
-
- Knows some wx things
- Posts: 40
- Joined: Wed Jun 01, 2005 3:52 am
i would read this document, since it appears to have some real good helpful advice for your current circumstance...
http://alug.appstate.edu/index.php?modu ... evelopment
http://alug.appstate.edu/index.php?modu ... evelopment
-
- Knows some wx things
- Posts: 31
- Joined: Wed May 24, 2006 12:45 am
- Contact:
I am sorry, but i can't find the "some real good helpful advice" anywhere.Dandel1984 wrote:i would read this document, since it appears to have some real good helpful advice for your current circumstance...
http://alug.appstate.edu/index.php?modu ... evelopment
Do I have to login that page?
-
- Knows some wx things
- Posts: 40
- Joined: Wed Jun 01, 2005 3:52 am
i said to read that, because if you read that, and then read this page, you get a real good idea as to what happens...liangbowen wrote:I am sorry, but i can't find the "some real good helpful advice" anywhere.Dandel1984 wrote:i would read this document, since it appears to have some real good helpful advice for your current circumstance...
http://alug.appstate.edu/index.php?modu ... evelopment
Do I have to login that page?
http://www.wxwindows.org/manuals/2.6.3/ ... xapponexit
-
- Knows some wx things
- Posts: 31
- Joined: Wed May 24, 2006 12:45 am
- Contact:
-
- Knows some wx things
- Posts: 40
- Joined: Wed Jun 01, 2005 3:52 am
all that i was pointing out is how to set wxwidgets with a shut off routine that can be used with the initialization routine... and as for the wxsock api it's up to you, but personally using libsdl wouldn't hurt for the network api.liangbowen wrote:Do you mean I should read the wxWidgets manual, I should use the wxSockXxxx API? Currently I only use wxWidgets as a GUI solution.
I don't quite get your point.
-
- Knows some wx things
- Posts: 31
- Joined: Wed May 24, 2006 12:45 am
- Contact: