All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.gdface.thrift.ServiceUtil Maven / Gradle / Ivy

There is a newer version: 2.10.3
Show newest version
package net.gdface.thrift;

import java.net.SocketAddress;

import com.facebook.nifty.core.ConnectionContext;
import com.facebook.nifty.core.RequestContext;
import com.facebook.nifty.core.RequestContexts;

/**
 * @author guyadong
 *
 */
public class ServiceUtil {
	private ServiceUtil() {}
	/**
	 * 返回客户端IP地址
	 * @return 客户端IP地址
	 */
	public static final SocketAddress niftyClientAddress(){
		RequestContext request = RequestContexts.getCurrentContext();
		if(null == request){
			return null;
		}
		ConnectionContext connect = request.getConnectionContext();
		return connect.getRemoteAddress();	
	}
	public static final String clientAddressAsString(){
		SocketAddress address = niftyClientAddress();
		return null == address ? "unknow" :address.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy