To retrieve the server port number, use the function $$ServerPort .When the port number does not have any value, it returns zero.
Every instance cannot have same port number. However, it can vary if they are executed from different folders with different settings, or modified after the instance is executed.