Jump to content
  • Advertisement
Sign in to follow this  
polyfrag

Sending struct sockaddr

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

I'm making a matchmaker/game-finding server and I want to send the game servers' addresses to clients. Can I send the sockaddr/sockaddr_in struct? And I want to be able to test from several instances on the SAME computer.

Share this post


Link to post
Share on other sites
Advertisement

Sending the full sockaddr_in struct is not necessarily going to be cross-platform, but if it's the same executable compiled by the same compiler and headers/libraries on the two machines, it would work.

Better would be to send the sin_addr and the sin_port field of the sockaddr_in, assuming you're dealing with ipv4 addresses.

 

Several instances on the same computer would work if your router/gateway/NAT box supports "hairpin NAT," which is not guaranteed for residential boxes. Support seems anecdotally to be spotty -- on the order of 30-50%. Solutions to that problem would include detecting multiple clients behind the same NAT and introducing them using their NAT-specific private address in that case.

Share this post


Link to post
Share on other sites

Do the simplest thing which could possibly work, which is probably using a text-based protocol and sending a string.

 

Text-based protocols for the win!

 

Seriously though, if it's a non-realtime thing such as a "server list" server (meta server) then you really want to use text-based protocols, probably http(s) is good. So send the IP address as a string (bonus: this allows you to also use IPv6 with no change in the protocol)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!