Code example for ServerSocket

Methods: getLocalPort

0
		private Socket socket;
 
		public TCPServerThread(InetAddress addr, int port)
				throws IOException { 
			try { 
				serverSocket = new ServerSocket(port, 1, addr);
			} catch (IOException e) {
				if (port == 0)
					throw e;
			} 
			// fall back on any available port 
			if (serverSocket == null)
				serverSocket = new ServerSocket(0, 1, addr);
		} 
 
		public int getLocalPort() { 
			return serverSocket.getLocalPort();
		} 
 
		@Override 
		protected void runIO() throws IOException { 
			socket = serverSocket.accept();