net.gdface.thrift.ServiceUtil Maven / Gradle / Ivy
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