Code example for ServerSocket

Methods: getLocalPort, isBound

0
	} 
 
	/** Initialize a server socket for communicating with the client. */ 
	private void initServerSocket() { 
		try { 
			this.serverSocket = new java.net.ServerSocket(COMM_PORT);
			assert this.serverSocket.isBound();
			if (this.serverSocket.isBound()) {
				System.out.println("SERVER inbound data port "
						+ this.serverSocket.getLocalPort()
						+ " is ready and waiting for client to connect..."); 
			} 
		} catch (SocketException se) {
			se.printStackTrace();
			System.exit(1);
		} catch (IOException ioe) {
			ioe.printStackTrace();
			System.exit(1);
		} 
	}