Over the past few years at game conferences we've talked a lot about the Xbox LIVE service and the many great oppourtunities on Xbox 360, Windows, and Windows Phone using it. What we've talked less about in these venues are best practices for those writing their own multiplayer clients and servers. While the glory days of DirectPlay are long past (it was a great technology when you had to contend with head-to-head modem play, direct serial connections, TCP/IP over modem, IPX/SPX, and TCP/IP all at once), there's more to Windows networking than WinSock 2.

 

Windows Firewall

The Windows Firewall included in Windows XP Service Pack 2 was a big part of the network security work for this release, and this firewall is still in place in current versions of Windows. For pure clients, there's not much to do but it does have impact on servers and peer-to-peer communications.

Windows Firewalls for Game Developers (DirectX SDK)

Games, Firewalls and Microsoft Windows XP SP2 (Meltdown 2004 presentation in the Windows Track)

Related FirewallInstallHelper sample

 

IPV6

Microsoft has invested heavily in preparing for the IPV6 Internet, including a IPV4/IPV6 dual-stack in the current generation of operating systems even including Windows XP Service Pack 3. While most games and game servers today are IPV4 only, moving your code to be 'IP-agnostic' is a good way to prepare for a transition to IPV6. Some great resources to start with are:

Creating IP Agonostic Applications part 1

Creating IP Agonostic Applications part 2

Related Connecting with IPv6 in Windows 8

 

Peer-to-peer Networking

Beyond just investing in IPV6, Microsoft has also built some technologies to improve peer-to-peer NAT traversal (called Teredo) and peer-to-peer name resolution (Peer Name Resolution Protocol aka PNRP). If you want to learn more, check out these resources:

Peer-to-peer networking blog

Peer to Peer Connectivity & Communications (Meltdown 2005 presentation in the Windows Track) 

 

InternetGetConnectedState

This legacy API dates back to Internet Explorer 4 and is used by some games to check for an active Internet connection. There is a much improved API for this available starting with Windows Vista called the Network List Manager API. A sample of using NLM is attached to the post.

If you still need a Windows XP fallback (i.e. the COM creation in the sample code will always fail), then you should remember that just because InternetGetConnectedState returns TRUE does not mean you have an active internet connection, You need to follow it up with an attempt to reach a known Internet location (via InternetOpen and InternetOpenUrl). If you are curious about how Windows 7 does it's "network connection available" test, check out this article.