Broadcast Addressing under Winsock

Started by
2 comments, last by mtemple 22 years, 4 months ago
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!"
Mark TempleEnemy Technology"We have found the enemy, and he is us!"
Advertisement
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)
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.
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!"
Mark TempleEnemy Technology"We have found the enemy, and he is us!"

This topic is closed to new replies.

Advertisement