The assigned port at the server can be obtained in the client side by
getLocalPort() method
getActivePort() method
By pinging the server
By giving value 0 as port number