Code example for Socket

Methods: getRemoteSocketAddress

0
	/** 
	 * Get the address of the remote socket as a String. 
	 * @return the address of the remote socket. 
	 */ 
	public String getRemoteAddress() {
		SocketAddress rsa = socket.getRemoteSocketAddress();
		String rsaString = "unknown";
		if ((rsa != null) && (rsa instanceof InetSocketAddress)) {
			rsaString = ((InetSocketAddress)rsa).getAddress().getHostAddress();
		} 
		return rsaString;
	} 
 
	/** 
	 * Determine whether the request was initiated by the LocalHost. 
	 * @return true if the request was initiated by the LocalHost; false otherwise. 
	 */ 
	public boolean isFromLocalHost() { 
		SocketAddress rsa = socket.getRemoteSocketAddress();
		if ((rsa != null) && (rsa instanceof InetSocketAddress)) {
			return ((InetSocketAddress)rsa).getAddress().isLoopbackAddress();