本文整理匯總了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()));
}
}
}
}