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


Java IoSession.setAttribute方法代码示例

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


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

示例1: getOrAddChannel

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
static MinaChannel getOrAddChannel(IoSession session, URL url, ChannelHandler handler) {
    if (session == null) {
        return null;
    }
    MinaChannel ret = (MinaChannel) session.getAttribute(CHANNEL_KEY);
    if (ret == null) {
        ret = new MinaChannel(session, url, handler);
        if (session.isConnected()) {
            MinaChannel old = (MinaChannel) session.setAttribute(CHANNEL_KEY, ret);
            if (old != null) {
                session.setAttribute(CHANNEL_KEY, old);
                ret = old;
            }
        }
    }
    return ret;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:MinaChannel.java

示例2: 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

示例3: 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

示例4: 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

示例5: messageReceived

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
  session.setAttribute(ProtocolCodecFilter.class.getName() + ".decoderOut", new MinaProtocolDecoderOutput(session, nextFilter));
  super.messageReceived(nextFilter, session, message);
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:5,代码来源:MinaProtocolCodecFilter.java


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