当前位置: 首页>>代码示例>>Java>>正文


Java IoSession.getRemoteAddress方法代码示例

本文整理汇总了Java中org.apache.mina.core.session.IoSession.getRemoteAddress方法的典型用法代码示例。如果您正苦于以下问题:Java IoSession.getRemoteAddress方法的具体用法?Java IoSession.getRemoteAddress怎么用?Java IoSession.getRemoteAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.core.session.IoSession的用法示例。


在下文中一共展示了IoSession.getRemoteAddress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIpAddr

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public static String getIpAddr(IoSession session) {
	if (session == null || session.getRemoteAddress() == null) {
		return "";
	}
	try {
		String ip = session.getRemoteAddress().toString();
		if (ip.indexOf(':') > 0) {
			ip = ip.substring(0, ip.indexOf(':'));
		} else {
			return "";
		}
		ip = ip.replace("/", "");
		return ip;
	} catch (Exception ex) {
		return "";
	}
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:18,代码来源:SessionUtils.java

示例2: isConnectionOk

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Method responsible for deciding if a connection is OK
 * to continue
 *
 * @param session
 *     The new session that will be verified
 * @return
 *     True if the session meets the criteria, otherwise false
 */
protected boolean isConnectionOk(IoSession session) {
    SocketAddress remoteAddress = session.getRemoteAddress();
    if (remoteAddress instanceof InetSocketAddress) {
        InetSocketAddress addr = (InetSocketAddress) remoteAddress;
        long now = System.currentTimeMillis();

        if (clients.containsKey(addr.getAddress().getHostAddress())) {

            LOGGER.debug("This is not a new client");
            Long lastConnTime = clients.get(addr.getAddress().getHostAddress());

            clients.put(addr.getAddress().getHostAddress(), now);

            // if the interval between now and the last connection is
            // less than the allowed interval, return false
            if (now - lastConnTime < allowedInterval) {
                LOGGER.warn("Session connection interval too short");
                return false;
            }

            return true;
        }

        clients.put(addr.getAddress().getHostAddress(), now);
        return true;
    }

    return false;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:39,代码来源:ConnectionThrottleFilter.java

示例3: isBlocked

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
private boolean isBlocked(IoSession session) {
    SocketAddress remoteAddress = session.getRemoteAddress();
    if (remoteAddress instanceof InetSocketAddress) {
        InetAddress address = ((InetSocketAddress) remoteAddress).getAddress();

        // check all subnets
        for (Subnet subnet : blacklist) {
            if (subnet.inSubnet(address)) {
                return true;
            }
        }
    }

    return false;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:16,代码来源:BlacklistFilter.java

示例4: getSessionAddress

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public static String getSessionAddress(IoSession session){
	if ( session == null ){
		return "" ;
	}
	if ( session.getRemoteAddress() == null || "".equals(session.getRemoteAddress())){
		return "" ;
	}
	String sessionAddress = session.getRemoteAddress().toString();
	sessionAddress = sessionAddress.substring(0, sessionAddress
			.indexOf(":"));
	return sessionAddress ;
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:13,代码来源:CommUtils.java

示例5: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    if (message instanceof IoBuffer) {
        IoBuffer buffer = (IoBuffer) message;
        String data = new String(buffer.array(), UTF_8);
        // ignore the discovery bytes response
        if (!data.contains("*") && data.length() >= 18) {
            String name = data.substring(8, 18);
            if (session.getRemoteAddress() instanceof InetSocketAddress) {
                cubes.add(new DiscoveredCube(name, ((InetSocketAddress) session.getRemoteAddress()).getHostString()));
            }
        }
    }
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:15,代码来源:MinaDiscoveryClient.java


注:本文中的org.apache.mina.core.session.IoSession.getRemoteAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。