當前位置: 首頁>>代碼示例>>Java>>正文


Java SocketChannel.getRemoteAddress方法代碼示例

本文整理匯總了Java中java.nio.channels.SocketChannel.getRemoteAddress方法的典型用法代碼示例。如果您正苦於以下問題:Java SocketChannel.getRemoteAddress方法的具體用法?Java SocketChannel.getRemoteAddress怎麽用?Java SocketChannel.getRemoteAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.channels.SocketChannel的用法示例。


在下文中一共展示了SocketChannel.getRemoteAddress方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: MysqlChannel

import java.nio.channels.SocketChannel; //導入方法依賴的package包/類
public MysqlChannel(SocketChannel channel) {
    this.sequenceId = 0;
    this.channel = channel;
    this.sendBuffer = ByteBuffer.allocate(2 * 1024 * 1024);
    this.isSend = false;

    // get remote description
    try {
        if (channel.getRemoteAddress() instanceof InetSocketAddress) {
            InetSocketAddress address = (InetSocketAddress) channel.getRemoteAddress();
            remote = address.getAddress().getHostAddress() + ":" + address.getPort();
        } else {
            // Reach here, what's it?
            remote = channel.getRemoteAddress().toString();
        }
    } catch (Exception e) {
        remote = "";
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:20,代碼來源:MysqlChannel.java

示例2: accept

import java.nio.channels.SocketChannel; //導入方法依賴的package包/類
/**
 * 接受新連接
 */
private void accept() {
	SocketChannel channel = null;
	try {
		channel = serverChannel.accept();
		channel.configureBlocking( false );
		
		// 構建Connection
		Connection c = factory.make(channel);
		c.setDirection( Connection.Direction.in );
		//c.setId( ConnectIdGenerator.getINSTNCE().getId() );
		
		InetSocketAddress remoteAddr = (InetSocketAddress) channel.getRemoteAddress();
		c.setHost(remoteAddr.getHostString());
		c.setPort(remoteAddr.getPort());
		
		// 將新連接派發至reactor進行異步處理
		NIOReactor reactor = reactorPool.getNextReactor();
		reactor.postRegister(c);

	} catch (Exception e) {
		LOGGER.warn(getName(), e);
		closeChannel(channel);
	}
}
 
開發者ID:variflight,項目名稱:feeyo-redisproxy,代碼行數:28,代碼來源:NIOAcceptor.java

示例3: addInNode

import java.nio.channels.SocketChannel; //導入方法依賴的package包/類
private void addInNode(SelectionKey key) {
    SocketChannel socketChannel = null;
    Node node = null;
    try {
        socketChannel = serverSocketChannel.accept();
        InetSocketAddress socketAddress = (InetSocketAddress) socketChannel.getRemoteAddress();
        if (!allowConnection(socketAddress)) {
            socketChannel.close();
            return;
        }
        socketChannel.configureBlocking(false);
        SelectionKey newKey = socketChannel.register(selector, SelectionKey.OP_READ);

        node = new Node(network, Node.IN, socketAddress);
        nodesManager.addNodeToGroup(NetworkConstant.NETWORK_NODE_IN_GROUP, node);
        ConnectionHandler handler = new ConnectionHandler(node, socketChannel, newKey);
        node.setWriteTarget(handler);
        newKey.attach(handler);
        node.connectionOpened();
    } catch (Exception e) {
        if (socketChannel != null) {
            Log.warn("in node Failed to connect" + node.getIp());
            try {
                socketChannel.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        if (node != null) {
            node.destroy();
        }
    }
}
 
開發者ID:nuls-io,項目名稱:nuls,代碼行數:34,代碼來源:ConnectionManager.java


注:本文中的java.nio.channels.SocketChannel.getRemoteAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。