Microsoft DirectX 9.0 SDK Update (Summer 2003) |
DirectPlay and Ports
This topic explains how to select a game port. Ports are an important part of addressing for Internet Protocol (IP) and Internetwork Packet Exchange (IPX) service providers. In cases where each computer has a unique IP address, the port specifies the application running on the computer. Microsoft® Windows® allows only one application per port. So if a user were playing a networked game, sending e-mail, and downloading files at the same time, each application would be bound to a different port. Each message received would have a port number in its address so that it could be passed to the correct application.
In cases where computers are behind a Network Address Translation (NAT) device and sharing a single public IP address, the port not only specifies the application but also the computer on which the application is running. So, if three computers sharing the same IP address were running the same application, each application would be bound to a different port, allowing messages to be delivered to the correct computer and application.
Also, if you specify a port, you don't need to use DPNSVR, which makes NAT device administration easier for users. Your application should choose a default port but allow users to override that port in case it is already in use. For more information about configuring game ports when players are behind NAT devices, see Network Address Translation, Firewalls, and Proxies.
Setting a Port
Set a port by calling the IDirectPlay8Address::AddComponent method. In the following example, port 12345 is selected.
IDirectPlay8Address* pAddress; DWORD dwPort; ... dwPort = 12345; hr = pAddress->AddComponent(DPNA_KEY_PORT, &dwPort, sizeof(dwPort),DPNA_DATATYPE_DWORD);
The port is specified as a DWORD, although the port number is limited to 65535 (2 bytes) and is used in host byte order. When selecting a port, do not choose a reserved port.
Ports Selected by DirectPlay
If you do not specify a port as described above, Microsoft DirectPlay® will select a port between 2302 and 2400 for local use when hosting, enumerating, or connecting. If hosts enable DPNSVR, the helper application will use port 6073 to forward enumeration queries to the application. This is also the default port number used when no port is specified in the remote host address passed to IDirectPlay8Peer::EnumHosts and IDirectPlay8Client::EnumHosts. And finally, if your application does not choose to disable the automated NAT features, you may notice additional ports being opened. The actual port numbers selected for this feature are not deterministic.
Reserved Ports
All ports under 1024 are reserved.
Also, DirectPlay has reserved the following ports.
Port | Reserved for |
---|---|
1900 | Universal Plug and Play (UPnP) - Simple Service Discovery Protocol |
2302-2400 | DirectPlay device address default |
2234 | Internet sharing and firewall support for Windows Millennium Edition (Windows Me) and Windows XP |
6073 | DirectPlay enumerations using DPNSVR |
47624 | Deprecated DirectPlay enumeration |
The Internet Assigned Numbers Authority maintains a list of registered User Datagram Protocol (UDP) ports that you should avoid using.