Setting Timeout In a Socket

Started by
3 comments, last by Galileo430 23 years, 2 months ago
I am trying to figure out how to set a timeout with a socket. For all you who know sockets you know how bad the mircosoft help files are. I don''t know if I even need a "timeout"!? Basicly what I am trying to do is,
  
//Here is some fake code

sendto(masterserver);
recvfrom(masterserver); //Wait 4 seconds before giving up on the responce

sendto(masterserver); // Send agian and so on..

  
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Advertisement
Hi Galileo430,
I assume your trying to build reliability into UDP, is this correct?

If so, your going to have to get a little bit more technical in your design to accomplish this.

Try doing a search for reliable UDP or something like that. If all else fails I can send you an outline that I h ave put together, I''m using this to write an article covering this topic.

Game On,


Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
use select , this function can set a timeout ..

but you may have to re-structure your code a bit.
I''m using a simple Windows timer. If the timer event occurs - I send a simple packet to test if the connection still exists. The socket should produce an error if the connection doesn''t exist no more.

Can I send a 0 size packet, to test for an existing connection?

With UDP you can send 0-sized packets. TCP will "optimize" them away...

cu,
Prefect

---
Sanity is the trademark of a weak mind.
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement