Method of using Server UDP Port

TODO: Re-translation is needed. Content is changed.

When client is connected to server then 1 TCP port will be appointed, which is nothing extraordinary since all TCP application programs are in this way.

However, ProudNet uses 1 UDP port for connecting with client. (If client can't use UDP port at default, then it uses TCP port instead.)

At that moment, Proud.CNetServer classifies the appointment policy of UDP port for each client connection.

  • Appoint all clients with each different UDP port.
  • Appoint all clients with already specified number of UDP ports.

The first is called per-client assign mode and the latter is called static assign mode.

At per-client assign mode, every client connecting to server will be appointed with each different UDP port. In this case, UDP port value will be used from one of UDP port numbers that server uses. If all of UDP port numbers are in use and more clients connect to server then random port numbers will be issued for them.

In static assign mode, there will be no case where another UDP port will be used than the list of UDP port numbers that server uses. And client connecting to that server will be appointed with one of UDP port numbers that server will use. This means, more than 2 clients will share the same UDP port in the manner of not affecting the flow of messages that could come from several clients on the same UDP port.

In general, per-client assign mode is better than static assign mode in performance-wise

  • When there are lot of clients in static assign mode, the relatively small numbers of UDP sockets must handle the excessive amount of client messages, which most likely to cause packet loss when the amount of internal buffers run short.
  • But if you prepare too many UDP sockets from the beginning then it could cause overloads in server and significantly increase the usage rate of memory and CPU.
  • Static assign mode is weak against ICMP host unreachable packet. So it has to be Firewall setup for ICMP related.

Unless it is inevitable, we recommend you to use per-client assign mode which doesn't have disadvantages listed above.

But there are some catches in using per-client assign mode. If the number of client trying to connect to server exceeds the number of UDP port that server will use, then they will be appointed with random ports, which coincidently match with numbers not permitted by firewall of that server. When this happens, the UDP communication may not perform appropriately.

Some server firewalls have a feature that allows the use of port as long as data is outbound packet. By using this, you can secure the performance of communication safely as using per-client assign mode although there are unpermitted UDP ports for use. For more details, please refer to Firewall setup to defend DDOS attack.

To decide which server will use which assign mode, you need to set Proud.CStartServerParameter.m_udpAssignMode when Proud.CNetServer.Start is called. And you can set the list of UDP ports that server will use from Proud.CStartServerParameter.m_udpPorts.

Summarizing everything mentioned above, the recommended ways to set assign mode, the length of UDP port list and firewall as using ProudNet are as followed.

Suggested level assign mode The length of UDP port list Firewall setup
Most suggested per-client 0 Permit when outbound packet is detected
Suggested per-client CCU(i.e.: 40000) Always permits numbers registered in UDP port list
Suggested static 1/10 of CCU(i.e.: 4000) Always permits numbers registered in UDP port list and blocks ICMP host unreachable.
Danger! Do not use this! per-client Insufficient to the maximum CCU(i.e.: 4000) Always permits numbers registered in UDP port list
Danger! Do not use this! static Irrelevant Irrelevant to the range of permitted UDP port and doesn't block ICMP host unreachable.