|Microsoft DirectX 9.0|
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.
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.
All ports under 1024 are reserved.
Also, Microsoft DirectPlay?has reserved the following ports.
|1900||Universal Plug and Play - 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.