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


Java IoSession.close方法代码示例

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


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

示例1: sessionClosed

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionClosed(IoSession session) throws Exception {
    MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    if (client != null) {
        try {
            boolean inCashShop = false;
            if (client.getPlayer() != null) {
                inCashShop = client.getPlayer().getCashShop().isOpened();                  
            }
            client.disconnect(false, inCashShop);
        } catch (Throwable t) {
            FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, t);
        } finally {
            session.close();
            session.removeAttribute(MapleClient.CLIENT_KEY);
            //client.empty();
        }
    }
    super.sessionClosed(session);
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:21,代码来源:MapleServerHandler.java

示例2: sessionClosed

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 连接关闭时触发
 */
@Override
public void sessionClosed(IoSession session) throws Exception {
	log.debug("服务端, session closed from " + session.getRemoteAddress());
    //TODO 关闭时触发删除客户端的ID序列值
	long id = session.getId();
	if(maps.containsKey(id)){
 	String uid = maps.get(id);
 	if(SessionMap.containsKey(uid)){
 		SessionMap.remove(uid);
 	}
 	maps.remove(id);
	}

    if(webCookie.containsKey(session)){
    	webCookie.remove(session);
    }
    session.close(true);
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:22,代码来源:DemuxingServerHandler.java

示例3: callNextExceptionCaught

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
private void callNextExceptionCaught(Entry entry, IoSession session, Throwable cause) {
    // Notify the related future.
    ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_CREATED_FUTURE);
    if (future == null) {
        try {
            IoFilter filter = entry.getFilter();
            NextFilter nextFilter = entry.getNextFilter();
            filter.exceptionCaught(nextFilter, session, cause);
        } catch (Throwable e) {
            LOGGER.warn("Unexpected exception from exceptionCaught handler.", e);
        }
    } else {
        // Please note that this place is not the only place that
        // calls ConnectFuture.setException().
        session.close(true);
        future.setException(cause);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DefaultIoFilterChain.java

示例4: sessionError

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
private void sessionError(IoSession session, String reason) {
	if (session == null) return;		
	
	synchronized(mutex) {
		
		if (!running.getFlag()) return;
		
		log.warning("SessionError: " + reason);		
		
		UnrealId source = null;
		
		synchronized(botSessions) {
			for (Entry<UnrealId, IoSession> entry : botSessions.entrySet()) {
				if (entry.getValue() == session) {
					source = entry.getKey();
					break;
				}
			}
		}	
		
		if (source != null) {
			botLeft(source); // will close the session as well!
		} else {			
			synchronized(session) {
				try {
					session.close(true);
				} catch (Exception e) {
					log.warning(ExceptionToString.process("Could not close the session... ???", e));
				}
			}
		}
		
	}
	
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:36,代码来源:TCMinaServer.java

示例5: kickPlayer

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public void kickPlayer(long playerId) {
	Player player = PlayerManager.getInstance().getOnlinePlayer(playerId);
	if (player == null) {
		return;
	}
	removeFromOnline(player);
	IoSession session = SessionManager.INSTANCE.getSessionBy(playerId);
	MessagePusher.pushMessage(session, new ResKickPlayerMessage());
	session.close(false);
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:11,代码来源:PlayerManager.java

示例6: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(IoSession session) throws Exception {
	String ipAddr = SessionManager.INSTANCE.getRemoteIp(session);
	if (!isInWhiteIps(ipAddr)) {
		logger.error("非法后台登录,remoteIp=[{}]", ipAddr);
		byte[] body = "too young too simple".getBytes("UTF-8");
		IoBuffer out = IoBuffer.allocate(body.length);
		out.put(body);
		out.flip();
		session.write(out);
		session.close(false);
	}
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:14,代码来源:HttpServer.java

示例7: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void messageReceived(IoSession session, Object message) throws Exception {

	String str = message.toString();
	System.out.println("接受到的消息:" + str);
	if (str.trim().equalsIgnoreCase("quit")) {
		session.close(true);
		return;
	}
	Date date = new Date();
	session.write(date.toString());
	System.out.println("Message written...");
}
 
开发者ID:handexing,项目名称:frameworkAggregate,代码行数:14,代码来源:TimeServerHandler.java

示例8: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(IoSession session) {
    if (!Server.getInstance().isOnline()) {
        session.close(true);
        return;
    }
    if (channel > -1 && world > -1) {
        if (Server.getInstance().getChannel(world, channel) == null) {
            session.close(true);
            return;
        }
    } else {
        FilePrinter.print(FilePrinter.SESSION, "IoSession with " + session.getRemoteAddress() + " opened on " + sdf.format(Calendar.getInstance().getTime()), false);
    }

    byte key[] = {0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, (byte) 0xB4, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00};
    byte ivRecv[] = {70, 114, 122, 82};
    byte ivSend[] = {82, 48, 120, 115};
    ivRecv[3] = (byte) (Math.random() * 255);
    ivSend[3] = (byte) (Math.random() * 255);
    MapleAESOFB sendCypher = new MapleAESOFB(key, ivSend, (short) (0xFFFF - ServerConstants.VERSION));
    MapleAESOFB recvCypher = new MapleAESOFB(key, ivRecv, (short) ServerConstants.VERSION);
    MapleClient client = new MapleClient(sendCypher, recvCypher, session);
    client.setWorld(world);
    client.setChannel(channel);
    session.write(MaplePacketCreator.getHello(ServerConstants.VERSION, ivSend, ivRecv));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:29,代码来源:MapleServerHandler.java

示例9: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened ( final IoSession session ) throws Exception
{
    try
    {
        final ServerConnection connection = this.server.createNewConnection ( session );
        session.setAttribute ( "connection", connection );
    }
    catch ( final Exception e )
    {
        session.write ( new CloseMessage ( "Failed to create server side connection: " + e, -1 ) );
        session.close ( false );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:ServerBaseHandler.java

示例10: doDecode

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, IoBuffer in, 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) {
        int packetHeader = in.getInt();
        if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
            session.close(true);
            return false;
        }
        decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
    } else if (in.remaining() < 4 && decoderState.packetlength == -1) {
        return false;
    }
    if (in.remaining() >= decoderState.packetlength) {
        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:NovaStory,项目名称:AeroStory,代码行数:30,代码来源:MaplePacketDecoder.java

示例11: sessionIdle

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public void sessionIdle(IoSession session, IdleStatus status)  throws Exception {
	System.out.println("sessionIdle……");
	if(session.isClosing()){
		System.out.println("sessionIdle      Closed");
	}else{
		if((System.currentTimeMillis()-session.getLastReadTime())>1000*60*2){
			System.err.println(session.getId()+"  ----------------Out of time, close user session");
			session.close(true);
		}
	}
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:12,代码来源:ServerHandler.java

示例12: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 当客户端收到服务器的消息后触发此方法.
 * @param session IoSession对象
 * @param message 客户端收到消息对象
 * @throws Exception
 */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    String str = message.toString();
    if (str.trim().equalsIgnoreCase("quit")) {
        session.close();
        return;
    }
    Date date = new Date();
    // 无论客户端发来什么消息,服务器只是把当前日期发送回去
    session.write(date.toString());
    System.out.println("Message written...");
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:19,代码来源:TimeServerHandler.java

示例13: exceptionCaught

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 当有异常发生时触发
 * 当 I/O 处理器的实现或是 Apache MINA 中有异常抛出的时候,此方法被调用。
 */
@Override
public void exceptionCaught(IoSession session, Throwable cause)
        throws Exception {
    System.out.println("服务端,发生异常" + cause.getMessage());
    map.remove(session.getId());
    session.close(true);
    //TODO 发生异常时保存客户端正在做的事情,以便客户端再次连接上来的时候返回给它
    //删除该客户端id序列值
    
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:15,代码来源:ServerHandler.java

示例14: handleExceptionCaught

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
protected void handleExceptionCaught ( final IoSession session, final Throwable cause )
{
    session.close ( true );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:5,代码来源:SlaveHost.java

示例15: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void messageReceived ( final NextFilter nextFilter, final IoSession session, final Object message ) throws Exception
{
    logger.debug ( "messageReceived - message: {}, session: {}", message, session ); //$NON-NLS-1$

    final boolean opened = isOpened ( session );

    if ( message instanceof HelloMessage && !opened && !this.clientMode )
    {
        // received hello when we need it
        final Object reply = createSession ( session, nextFilter, (HelloMessage)message );
        logger.info ( "Reply to session creation: {}", reply ); //$NON-NLS-1$

        if ( reply instanceof AcceptMessage )
        {
            this.acceptedProperties = Collections.unmodifiableMap ( ( (AcceptMessage)reply ).getProperties () );

            // configure the session, enable filters
            configureSession ( session, nextFilter, this.acceptedProperties );

            /*
             * send reply - this must be the first message after the configureSession call
             * so that filter can reset their initial flag. The first message must still be
             * un-filtered since the other side needs to adapt its filter chain first. However
             * this must be an atomic operation since sending and changing the filter in two
             * separate steps could mean that we already receive the reply to our ACCEPT
             * before we had a chance to change our filter chain. 
             */
            nextFilter.filterWrite ( session, new DefaultWriteRequest ( reply ) );

            // post configure the session
            postConfigureSession ( session, nextFilter, this.acceptedProperties );

            if ( isOpened ( session ) )
            {
                // if the session is marked "open" by the StartSessionHandshake, then notify the open state immediately
                startSession ( session, nextFilter );
            }
        }
        else
        {
            // send reply
            nextFilter.filterWrite ( session, new DefaultWriteRequest ( reply ) );
            // close - after message was sent
            session.close ( false );
        }
        dumpFilterChain ( session );
        logger.debug ( "Done handling HelloMessage" );
    }
    else if ( message instanceof AcceptMessage && !opened && this.clientMode )
    {
        this.acceptedProperties = Collections.unmodifiableMap ( ( (AcceptMessage)message ).getProperties () );
        configureSession ( session, nextFilter, this.acceptedProperties );
        postConfigureSession ( session, nextFilter, this.acceptedProperties );
        markOpened ( session );
        startSession ( session, nextFilter );
        dumpFilterChain ( session );
    }
    else if ( message instanceof CloseMessage )
    {
        // remote will close
        session.setAttribute ( "closeReason.message", ( (CloseMessage)message ).getMessage () ); //$NON-NLS-1$
        session.setAttribute ( "closeReason.code", ( (CloseMessage)message ).getCode () ); //$NON-NLS-1$
        session.close ( true );
    }
    else if ( message instanceof DataMessage && opened )
    {
        nextFilter.messageReceived ( session, message );
    }
    else if ( message instanceof StartMessage && !opened )
    {
        logger.debug ( "Starting session" );
        markOpened ( session );
        startSession ( session, nextFilter );
        dumpFilterChain ( session );
    }
    else
    {
        throw new IllegalStateException ( String.format ( "(opened: %s) Message type: %s", opened, message.getClass () ) ); //$NON-NLS-1$
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:82,代码来源:MessageChannelFilter.java


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