Here you can find the source of getPort(ServerSocket server)
public static int getPort(ServerSocket server)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.ServerSocket; public class Main { public static int getPort(ServerSocket server) { int port = server.getLocalPort(); try {//w ww. ja v a 2s .com server.close(); } catch (IOException e) { e.printStackTrace(); } return port; } }