Here you can find the source of getMyPortNumber(ServerSocket serverSocket)
public static int getMyPortNumber(ServerSocket serverSocket)
//package com.java2s; /*/*from w ww .j a va2s . c o m*/ * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 * International License (http://creativecommons.org/licenses/by-nc-nd/4.0/). */ import java.net.ServerSocket; public class Main { public static int getMyPortNumber(ServerSocket serverSocket) { return serverSocket.getLocalPort(); } }