Discovering hosts on a LAN?

Hi guys,

I’m working on a multiplayer game that will support LAN play. I would like to know the best way to implement host discovery on the LAN.

I think I know part of what needs to be done, though I would appreciate your thoughts. If a player decides to host a game, I assume I need to have that host do an IP broadcast to the LAN. If the player dissolves the game, then again I would guess that host needs to broadcast the fact to the LAN. (Can I do that using TCP, or do such broadcasts have to be UDP?)

The part where I’m not sure what to do is this. Suppose there are already games being staged on the LAN, and a new player joins the LAN. What is the best way for that player to be made aware of the games? Does the host need to issue periodic broadcasts, so that the new player learns of the game? If so, what is a good time interval? Or is there a better way to do it altogether?

Thanks,
Willie

p.s. Also, in case it’s not obvious from my previous post, there is no dedicated server on the LAN. Any player is a potential game host. So there is no central authority to query for available games.

Hm, after writing that I came up with an idea. What if when the new player joins the LAN, his client broadcasts a query to the LAN like “who has a game?” That prompts a response from any host on the LAN. (I guess that response doesn’t need to be broadcasted though.) I’m pretty sure that would work.

Is there a better or more standard way of doing this?

Thanks,
Willie

perhaps use an UDP broadcast ?

[quote]Hm, after writing that I came up with an idea. What if when the new player joins the LAN, his client broadcasts a query to the LAN like “who has a game?” That prompts a response from any host on the LAN. (I guess that response doesn’t need to be broadcasted though.) I’m pretty sure that would work.

Is there a better or more standard way of doing this?

Thanks,
Willie
[/quote]
this is fairly standard; the main reason is that if no-one ever joins then no extraneous packets are sent out. As opposed to your origingal proposal which involves sending out packets pointlessly (potentially).