本文整理汇总了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 "";
}
}
示例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;
}
示例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;
}
示例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 ;
}
示例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()));
}
}
}
}