In general, it is not possible to predict the port number used by a communications partner creating a TCP/IP connection.
The port number is always set by the operating system. A range of port numbers that can be used is defined by the TCP/IP standard and operating systems can have their own range. See also:
In the situation where the port number of a communication partner is defined (for example, JobScheduler uses 4444 and 59999). The partner opens the port in advance and waits for incoming connection requests. In that situation the partner has a passive server role. Port numbers are generally protected by firewalls as firewalls protect from incoming connections to particular ports.
Ports 59999 and less that are designated for API communication differ from the description above only in that they are dynamically allocated server ports. Why? JobScheduler opens such a port for every API process and thereby knows which starting API process is related to the port.