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


Java IoSession.isConnected方法代码示例

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


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

示例1: main

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public static void main(String[] args) {
	IoConnector connector = new NioSocketConnector();
	connector.getFilterChain().addLast("logger", new LoggingFilter());
	connector.getFilterChain().addLast("codec",
			new ProtocolCodecFilter(new PrefixedStringCodecFactory(Charset.forName("UTF-8"))));
	connector.setHandler(new TimeClientHander());
	ConnectFuture connectFuture = connector.connect(new InetSocketAddress("127.0.0.1", PORT));
	// 等待建立连接
	connectFuture.awaitUninterruptibly();
	System.out.println("连接成功");
	IoSession session = connectFuture.getSession();
	Scanner sc = new Scanner(System.in);
	boolean quit = false;
	while (!quit) {
		String str = sc.next();
		if (str.equalsIgnoreCase("quit")) {
			quit = true;
		}
		session.write(str);
	}

	// 关闭
	if (session != null) {
		if (session.isConnected()) {
			session.getCloseFuture().awaitUninterruptibly();
		}
		connector.dispose(true);
	}

}
 
开发者ID:handexing,项目名称:frameworkAggregate,代码行数:31,代码来源:MimaTimeClient.java

示例2: writeData

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Actually write data. Queues the data up unless it relates to the handshake or the 
 * handshake is done.
 * 
 * @param nextFilter the next filter in filter chain
 * @param session the session object
 * @param writeRequest the data to write
 * @param isHandshakeData true if writeRequest is written by the proxy classes.
 */
public void writeData(final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest,
        final boolean isHandshakeData) {
    ProxyLogicHandler handler = getProxyHandler(session);

    synchronized (handler) {
        if (handler.isHandshakeComplete()) {
            // Handshake is done - write data as normal
            nextFilter.filterWrite(session, writeRequest);
        } else if (isHandshakeData) {
            LOGGER.debug("   handshake data: {}", writeRequest.getMessage());

            // Writing handshake data
            nextFilter.filterWrite(session, writeRequest);
        } else {
            // Writing non-handshake data before the handshake finished
            if (!session.isConnected()) {
                // Not even connected - ignore
                LOGGER.debug(" Write request on closed session. Request ignored.");
            } else {
                // Queue the data to be sent as soon as the handshake completes
                LOGGER.debug(" Handshaking is not complete yet. Buffering write request.");
                handler.enqueueWriteRequest(nextFilter, writeRequest);
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:36,代码来源:ProxyFilter.java

示例3: filterWrite

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws SSLException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("{}: Writing Message : {}", getSessionInfo(session), writeRequest);
    }

    boolean needsFlush = true;
    SslHandler handler = getSslSessionHandler(session);
    synchronized (handler) {
        if (!isSslStarted(session)) {
            handler.scheduleFilterWrite(nextFilter, writeRequest);
        }
        // Don't encrypt the data if encryption is disabled.
        else if (session.containsAttribute(DISABLE_ENCRYPTION_ONCE)) {
            // Remove the marker attribute because it is temporary.
            session.removeAttribute(DISABLE_ENCRYPTION_ONCE);
            handler.scheduleFilterWrite(nextFilter, writeRequest);
        } else {
            // Otherwise, encrypt the buffer.
            IoBuffer buf = (IoBuffer) writeRequest.getMessage();

            if (handler.isWritingEncryptedData()) {
                // data already encrypted; simply return buffer
                handler.scheduleFilterWrite(nextFilter, writeRequest);
            } else if (handler.isHandshakeComplete()) {
                // SSL encrypt
                int pos = buf.position();
                handler.encrypt(buf.buf());
                buf.position(pos);
                IoBuffer encryptedBuffer = handler.fetchOutNetBuffer();
                handler.scheduleFilterWrite(nextFilter, new EncryptedWriteRequest(writeRequest, encryptedBuffer));
            } else {
                if (session.isConnected()) {
                    // Handshake not complete yet.
                    handler.schedulePreHandshakeWriteRequest(nextFilter, writeRequest);
                }
                needsFlush = false;
            }
        }
    }

    if (needsFlush) {
        handler.flushScheduledEvents();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:46,代码来源:SslFilter.java

示例4: onSessionClosed

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void onSessionClosed(IoSession session) {
	if (session != null && session.isConnected())
		session.closeOnFlush();
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:6,代码来源:ProxyBiz.java


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