Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Metus

Ping TCP

This topic is 5765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi again. since my last post i''ve implemented a server/client application with support for 10 + 1 dummy socket connection. my next dilemma is about the connection lifetime. is there any simple way to test a connection from client to server and server to client or do i have to write my own ping-pong function? isn''t TCP smart enough for that?

Share this post


Link to post
Share on other sites
Advertisement
For what condition do you want to "test" the connection? If the connection goes down (error, or client/server closed it) you will be alerted in such way that read() will return 0 even when the system said it was data to be received.

However, to see that the client/server is awake, you should implement some sort of NOOP command, thet either can send to the other which then respond with an OK.


Share this post


Link to post
Share on other sites
I'm assuming its a persistant connection(eg: a game, IRC server), so implementing your own ping-pong system would enable other users to see the latency of other users(either as a point for heckling their connection or locating transfer problems).

If you don't know, an IRC server sends out a ping packet like so:

PING [random number]

And to respond the client sends:

PONG [the same number]

You just start timing from when you send the PING and stop when you recieve the PONG, if the timeout goes too high (20seconds), then boot the user.

[edited by - Zanthos on February 8, 2003 5:57:48 AM]

Share this post


Link to post
Share on other sites
well, as i said i''ve implemented a server with (at the moment) max 10 connections. and if one of those connections dies (timed-out, connection lost) i want to "release" that connection so a new connection can be established.

i was just wondering if there were any special methods to test the connectivity, but as you stated, if recv returns 0 the connection was either lost or no data was sent...
i''ve planned to send data only when a state has changed (like the player moved, got hurt or died)

Share this post


Link to post
Share on other sites
quote:
Original post by Zanthos
I''m assuming its a persistant connection(eg: a game, IRC server), so implementing your own ping-pong system would enable other users to see the latency of other users(either as a point for heckling their connection or locating transfer problems).

If you don''t know, an IRC server sends out a ping packet like so:

PING

And to respond the client sends:

PONG <the same number>

You just start timing from when you send the PING and stop when you recieve the PONG, if the timeout goes too high (20seconds), then boot the user.



yes, it is a simple game server... i''ve got a might-be scheme like this:

1. loop through all the connections
2. ping each connection with the "connected = true" state
3. start an unique timer
4. wait for pong
5. if no pong reply or high pong-time, close the connetion

Share this post


Link to post
Share on other sites
quote:
Original post by Metus
1. loop through all the connections
2. ping each connection with the "connected = true" state
3. start an unique timer
4. wait for pong
5. if no pong reply or high pong-time, close the connetion
Probably a good one. What socket technique do you use? Blocking? Non-blocking? Asyncronous? Threaded?




Share this post


Link to post
Share on other sites
well, this is the first time at all i code sockets so i''m using the windows standard, but however, i''m using WSAAsyncSelect so i''d guess its a hybrid =)
i''m planning to use threaded UDP as soon as i get this to work... if ever

Share this post


Link to post
Share on other sites
Ok, then I think what you proposed would suffice. Have a field in each connection object (or whatever you store connection info in) that tells if the client has "ponged in" and clear it. Then, send out the "ping" to all active connections, and set a timer so you get a message to your window proc when the time-out is. When you get the "pong" you somehow mark that client to have done just that. When you get your time-out message, check all connections, and kill off those who didn''t "pong". Then start over.


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!