Archived

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

Broadcast Addressing under Winsock

This topic is 5848 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

Gents, Has anyone tried sending and receiving broadcast packets under Winsock 2.0? Is there a trick to it? I am converting some older code from IPX to Winsock and in that old system, the Host machine would use broadcast packets to advertise his game, and then switch to directed packets once a client had joined up. Are broadcast packets still the preferred method for connecting players up via LAN? Via the Internet? I have tested my Winsock code extensively with directed packets and it works fine. But this is the first time I have specified a broadcast address and nothing seems to be getting through. It is possible that the problem is in the game code somewhere, but I just wanted to be sure that broadcast addressing under Winsock is not a total nightmare before I proceed. Thanks in advance. Mark Temple Enemy Technology "We have found the enemy, and he is us!"

Share this post


Link to post
Share on other sites
why not just use a central directory for servers? ok bad idea on a small lan with few servers.

basically it is up to the client to find the server not the server to find the client. so instead of having the server to send packets, have the clients send them. the best way on a lan to find games is to just send a broadcast udp packet which acts as a ping. then have the client what x number of seconds for responses. all responses should tell the client the ip:port (just in case the server is running on non defualt port)/server name/game mode/etc. this of course assumes that ALL servers will listen for broadcast packets on a hardcoded port. you may want to do things differently. if you have a packet sniffer you may want to see how other games handle this. or even checking out the iplmentation of quake (since its ource was released)

Share this post


Link to post
Share on other sites
a person is right. Generally, you''d want the clients to broadcast that they''re looking for a game when the player goes to the ''join network game'' screen. There''s no need for the server to send out broadcasts every second or however often if no clients are even out there to connect.

As for why it may not be working... are you calling setsockopt() with SO_BROADCAST for the socket you''re trying to broadcast from? That''s a big gotcha for broadcasting with winsock.

Share this post


Link to post
Share on other sites
Thank you both for the information. It is really not very difficult for me to have the clients broadcast instead of the server as suggested, so I''ll go ahead and do that. I assume from your responses that broadcast packets are not taboo so I feel a little better. I am aware that I need to call setsockopt() but since the code I used as a base did not do this, it is possible that I forgot about it. A good thought!
Again, thanks for the help and for setting my mind at ease about broadcast packets. Man, this is the best net site for game development help! I''ve been saved over and over again!


Mark Temple
Enemy Technology

"We have found the enemy, and he is us!"

Share this post


Link to post
Share on other sites