当前位置: 首页>>代码示例>>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;未经允许,请勿转载。