當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。