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


Java IoSession.close方法代码示例

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


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

示例1: sessionOpened

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(final IoSession session) throws Exception {
	
    // Start of IP checking
    final String address = session.getRemoteAddress().toString().split(":")[0];
    final short port = Short.parseShort(session.getServiceAddress().toString().split(":")[1]);
    
    if (LoginServer.isShutdown()) {
        session.close();
        return;
    }

    // IV used to decrypt packets from client.
    final byte ivRecv[] = new byte[]{(byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255)};
    
    // IV used to encrypt packets for client.
    final byte ivSend[] = new byte[]{(byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255)};

    MapleClient client = new MapleClient(
            new MapleAESOFB(skey, ivSend, (short) (0xFFFF - ServerConstants.MAPLE_VERSION)),
            new MapleAESOFB(skey, ivRecv, ServerConstants.MAPLE_VERSION), session);
    client.setChannel(-1);

    MaplePacketDecoder.DecoderState decoderState = new MaplePacketDecoder.DecoderState();
    session.setAttribute(MaplePacketDecoder.DECODER_STATE_KEY, decoderState);
    
    session.write(LoginPacket.getHello(ServerConstants.MAPLE_VERSION, ivSend, ivRecv));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
    session.setIdleTime(IdleStatus.READER_IDLE, 60);
    session.setIdleTime(IdleStatus.WRITER_IDLE, 60);

    System.out.println("Connection Established " + address + ":"+port);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:34,代码来源:MapleServerHandler.java

示例2: sessionClosed

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionClosed(final IoSession session) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        byte state = MapleClient.CHANGE_CHANNEL;
        if (!LoginServer.isShutdown() && client.getPlayer() != null) {
            state = client.getLoginState();
        }
        if (state != MapleClient.CHANGE_CHANNEL) {
            if (System.currentTimeMillis() - lastDC < 60000) { //within the minute
                numDC++;
                if (numDC > 100) { //100+ people have dc'd in minute in channelserver
                    System.out.println("Writing log...");
                    numDC = 0;
                    lastDC = System.currentTimeMillis(); // intentionally place here
                }
            } else {
                numDC = 0;
                lastDC = System.currentTimeMillis(); // intentionally place here
            }
        }
        
        session.close();
        client.disconnect(true, false);
        session.removeAttribute(MapleClient.CLIENT_KEY);
    }
    super.sessionClosed(session);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:30,代码来源:MapleServerHandler.java

示例3: doDecode

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
    final DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);

    /*	if (decoderState == null) {
     decoderState = new DecoderState();
     session.setAttribute(DECODER_STATE_KEY, decoderState);
     }*/
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (decoderState != null) {
    	if (decoderState.packetlength == -1) {
            if (in.remaining() >= 4) {
                final int packetHeader = in.getInt();
                if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
                    session.close();
                    return false;
                }
                decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
            } else {
                return false;
            }
        }
        if (in.remaining() >= decoderState.packetlength) {
            final byte decryptedPacket[] = new byte[decoderState.packetlength];
            in.get(decryptedPacket, 0, decoderState.packetlength);
            decoderState.packetlength = -1;

            client.getReceiveCrypto().crypt(decryptedPacket);
            // MapleCustomEncryption.decryptData(decryptedPacket);
            out.write(decryptedPacket);
            return true;
        }
    }
    return false;
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:37,代码来源:MaplePacketDecoder.java

示例4: doDecode

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
protected boolean doDecode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);

    if (decoderState == null) {
        decoderState = new DecoderState();
        session.setAttribute(DECODER_STATE_KEY, decoderState);
    }

    if (in.remaining() >= 4 && decoderState.packetlength == -1) {
        final int packetHeader = in.getInt();
        if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
            System.err.println(MapleClient.getLogMessage(client, "Client failed packet check -> disconnecting"));
            session.close();
            return false;
        }
        decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
    } else if (in.remaining() < 4 && decoderState.packetlength == -1) {
        //System.err.println("decode... not enough data");
        return false;
    }

    if (in.remaining() >= decoderState.packetlength) {
        final byte[] decryptedPacket = new byte[decoderState.packetlength];
        in.get(decryptedPacket, 0, decoderState.packetlength);
        decoderState.packetlength = -1;

        client.getReceiveCrypto().crypt(decryptedPacket);
        MapleCustomEncryption.decryptData(decryptedPacket);
        out.write(decryptedPacket);

        return true;
    } else {
        //System.err.println("decode... not enough data to decode (need " + decoderState.packetlength + ")");
        return false;
    }
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:39,代码来源:MaplePacketDecoder.java

示例5: sessionOpened

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(final IoSession session) throws Exception {
    //log.info("IoSession with {} opened", session.getRemoteAddress());
    if (channel > -1) {
        if (ChannelServer.getInstance(channel).isShutdown()) {
            session.close();
            return;
        }
    }
    final byte[] key = {
        (byte) 0x13, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0xB4, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x1B, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x0F, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x33, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x52, (byte) 0x00, (byte) 0x00, (byte) 0x00
    };
    final byte[] ivRecv = {(byte) 70, (byte) 114, (byte) 122, (byte) 82};
    final byte[] ivSend = {(byte) 82, (byte) 48, (byte) 120, (byte) 115};
    ivRecv[3] = (byte) (Math.random() * 255.0d);
    ivSend[3] = (byte) (Math.random() * 255.0d);
    final MapleAESOFB sendCypher = new MapleAESOFB(key, ivSend, (short) (0xFFFF - MAPLE_VERSION));
    final MapleAESOFB recvCypher = new MapleAESOFB(key, ivRecv, MAPLE_VERSION);
    final MapleClient client = new MapleClient(sendCypher, recvCypher, session);
    client.setChannel(channel);
    session.write(MaplePacketCreator.getHello(MAPLE_VERSION, ivSend, ivRecv, false));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
    session.setIdleTime(IdleStatus.READER_IDLE, 30);
    session.setIdleTime(IdleStatus.WRITER_IDLE, 30);
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:33,代码来源:MapleServerHandler.java

示例6: exceptionCaught

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void exceptionCaught(IoSession session, Throwable cause)
		throws Exception {
	if (LOGGER.isWarnEnabled())
		LOGGER.warn("connection exception occured", cause);
	
	if(!(cause instanceof IOException)){
		session.close();
	}
}
 
开发者ID:alibaba,项目名称:tair-java-client,代码行数:11,代码来源:TairClientProcessor.java

示例7: exceptionCaught

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void exceptionCaught(IoSession session, TairClientException exception) {
  log.error("do async request failed", exception);
  if (session.isConnected()) {
  	log.error("session closing");
  	session.close();
  }
  masterFailCount++;
}
 
开发者ID:alibaba,项目名称:tair-java-client,代码行数:9,代码来源:ConfigServer.java

示例8: exceptionCaught

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
    // close invalid session
    if (session != null) {
        LOG.debug("Closing session as an exception was thrown from MINA");
        session.close();
    }

    // must wrap and rethrow since cause can be of Throwable and we must only throw Exception
    throw new CamelException(cause);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:MinaConsumer.java

示例9: exceptionCaught

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void exceptionCaught(IoSession ioSession, Throwable cause) {
    LOG.error("Exception on receiving message from address: " + this.endpoint.getAddress()
            + " using connector: " + this.endpoint.getConnector(), cause);
    this.message = null;
    this.messageReceived = false;
    this.cause = cause;
    if (ioSession != null) {
        ioSession.close();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:MinaProducer.java

示例10: sessionOpened

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void sessionOpened(IoSession session) throws Exception {
    session.write("Hello there!\n");
    session.close();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:5,代码来源:MinaClientModeTcpTextlineDelimiterTest.java

示例11: exceptionCaught

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void exceptionCaught(IoSession session, Throwable cause) {
    cause.printStackTrace();
    // Close connection when unexpected exception is caught.
    session.close();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:ReverseProtocolHandler.java


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