當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。