Read an Excerpt
Chapter 13: DirectPlay OverviewIn this chapter, the communications aspect of DirectX is explored, along with certain other features of the Win32 API. We discuss the new features of DirectPlay 6, the DirectPlay architecture, the protocols encapsulated by DirectPlay, multithreading, event handling, lobbies, and other related topics. The chapter finishes up with a simple chat program. By the end of this chapter readers should feel comfortable enough with the above mentioned issues to add networking support to an application using the DirectPlay interface.
Why Is Using DirectPlay Desirable?Those who are going to be writing networking code for the Windows platform, or any platform, will need to decide which protocol to use, whether to use a peer-to-peer or client/server architecture, how data will be packaged, how data will be sent and received, etc. Those who are writing a networked game might also want to provide a user-friendly interface for allowing the host player to select which protocol to use, and any required connection settings needed to begin a multiplayer game. DirectPlay facilitates this communications process by providing a standard interface to the different protocols it encapsulates. This and other benefits of using DirectPlay are fisted below:
- There is consistent programming interface for providing networking capabilities over a range of protocols/transports-TCP/IP, IPX, Modem (TAPI), or Serial
- All the functionality provided by DirectPlay is supported, regardless of whether the underlying network supports the functionality. Functionality is emulated by the DirectPlay object if the underlying network does not support a specificmethod.
- There is client/server or peer-to-peer networking support
- Creation of players and groups is supported
- There is session management for ease of connecting to open sessions.
- Support for secure communications
- Lobby support provides a more user-friendly interface for launching a multiplayer application
- Chat message support is built in.
The above list of items is only a subset of the functionality that DirectPlay provides. The following section will detail the new features in DirectPlay 6.
What Is New in DirectPlay 6DirectPlay 6 addresses some issues especially standardization, that will continue to enhance it as the game networking API of choice. Many of the online gaming networks support DirectPlay, and integrating an application with these networks is simple using the DirectPlay API. Such online gaming networks as Heat and the Microsoft Internet Gaming Zone use the lobby support provided by DirectPlay to integrate a user-friendly interface into a multiplayer application. This integration provides an easy and efficient mechanism for one player to find others who are interested in a multiplayer game.
The new features added to DirectPlay are listed below.
- Guaranteed messaging is supported via the DirectPlay protocol, which provides guaranteed messaging regardless of the underlying service provider. Under the previous version of DirectPlay, guaranteed messaging was only supported if the underlying service provider supported it. Use the DirectPlay protocol for messaging, even when the underlying protocol supports guaranteed messaging, to help improve the communication channel's efficiency. The DirectPlay protocol does not wait for a message acknowledgement before sending the next message. Messages can be prioritized as well, and dynamic reporting of network latency is provided.
- Asynchronous messaging is supported to help minimize the delay experienced in work with guaranteed service providers. The application's receive message queue is notified as to the success or failure of a particular message. It is also possible to cancel a message that has been sent asynchronously.
- Message throttling is provided to help prevent sending out more messages than what the underlying network is supporting. Both the send and receive queues can be checked to see how the application is responding across different types of network connections. During the course of an application, it is possible periodically to check the send queue to see if messages are backing up, and if so, throttle back the number of messages being sent out. In theory this sounds simple, but in practice it may prove to be a hair-pulling experience. Message throttling is dependent on the application's complexity, structure, and network requirements.
- Firewall support for the TCP/IP protocol is provided. By using a range of pre-defined ports, DirectPlay makes the firewall support transparent to the developer and end-user, requiring only that the network administrator open up these ports in the firewall. The trick is getting the network administrator to agree to open the ports. The end-user may have to specify certain settings via the control panel.
- Improved lobby support for detecting when the host of a session has migrated allows for new players to join a session already in progress. Rerouting of lobby messages by an external lobby client is no longer required, and the Connect: function has a timeout of one minute.
- Security has been extended to peer-to-peer network sessions, and secure messages can now be sent to groups.
- Lobby application registration has been moved from the setup portion of DirectX into the DirectPlay interface.
- There is improved localization support for applications that may end up being run on machines using multibyte strings instead of single-byte strings.
- Improved keep-alive support allows the service provider to notify DirectPlay that a player or session has been lost, so the application can take appropriate action.
- Service providers can specify that they are private, thereby preventing them from being viewed. These providers are only accessible if their GUID is known.
- There is a wait mode for DirectPlay applications. Instead of the lobby's launching a new instance of the application, it can send the connection settings to a waiting instance of the application. . . .