本文整理了Java中java.nio.channels.SocketChannel.getRemoteAddress()
方法的一些代码示例,展示了SocketChannel.getRemoteAddress()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.getRemoteAddress()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:getRemoteAddress
暂无
代码示例来源:origin: lealone/Lealone
public NioWritableChannel(SocketChannel channel, NioEventLoop nioEventLoop) throws IOException {
this.channel = channel;
this.nioEventLoop = nioEventLoop;
SocketAddress sa = channel.getRemoteAddress();
if (sa instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) sa;
host = address.getHostString();
port = address.getPort();
} else {
host = "";
port = -1;
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public HandlerState call()
throws Exception {
SocketChannel client = this.server.accept();
LOG.info("Accepted connection from {}", client.getRemoteAddress());
try {
new ProxySetupHandler(client, selector, config);
} catch (IOException ioe) {
client.close();
}
return HandlerState.ACCEPTING;
}
}
代码示例来源:origin: Netflix/EVCache
@Override
public String getSocketChannelRemoteAddress() {
try {
if(getChannel() != null) {
return getChannel().getRemoteAddress().toString();
}
} catch (IOException e) {
log.error("Exception", e);
}
return "NULL";
}
代码示例来源:origin: apache/nifi
public SSLSocketChannel(final SSLEngine sslEngine, final SocketChannel socketChannel) throws IOException {
if (!socketChannel.isConnected()) {
throw new IllegalArgumentException("Cannot pass an un-connected SocketChannel");
}
this.channel = socketChannel;
this.socketAddress = socketChannel.getRemoteAddress();
final Socket socket = socketChannel.socket();
this.hostname = socket.getInetAddress().getHostName();
this.port = socket.getPort();
// don't set useClientMode or needClientAuth, use the engine as is and let the caller configure it
this.engine = sslEngine;
streamInManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize()));
streamOutManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize()));
appDataManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getApplicationBufferSize()));
}
代码示例来源:origin: apache/nifi
public SSLSocketChannel(final SSLContext sslContext, final SocketChannel socketChannel, final boolean client) throws IOException {
if (!socketChannel.isConnected()) {
throw new IllegalArgumentException("Cannot pass an un-connected SocketChannel");
}
this.channel = socketChannel;
this.socketAddress = socketChannel.getRemoteAddress();
final Socket socket = socketChannel.socket();
this.hostname = socket.getInetAddress().getHostName();
this.port = socket.getPort();
this.engine = sslContext.createSSLEngine();
this.engine.setUseClientMode(client);
this.engine.setNeedClientAuth(true);
streamInManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize()));
streamOutManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize()));
appDataManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getApplicationBufferSize()));
}
代码示例来源:origin: wildfly/wildfly
public String toString() {
InetSocketAddress local=null, remote=null;
try {local=channel != null? (InetSocketAddress)channel.getLocalAddress() : null;} catch(Throwable t) {}
try {remote=channel != null? (InetSocketAddress)channel.getRemoteAddress() : null;} catch(Throwable t) {}
String loc=local == null ? "n/a" : local.getHostString() + ":" + local.getPort(),
rem=remote == null? "n/a" : remote.getHostString() + ":" + remote.getPort();
return String.format("<%s --> %s> (%d secs old) [%s] [recv_buf: %d, reader=%b]",
loc, rem, TimeUnit.SECONDS.convert(getTimestamp() - last_access, TimeUnit.NANOSECONDS),
status(), recv_buf.get(1) != null? recv_buf.get(1).capacity() : 0, readerRunning());
}
代码示例来源:origin: wildfly/wildfly
SocketChannel client_ch=ch.accept();
if(client_ch != null) { // accept() may return null...
System.out.printf("accepted connection from %s\n", client_ch.getRemoteAddress());
client_ch.configureBlocking(false);
client_ch.register(selector, SelectionKey.OP_READ, create(SIZE, direct));
代码示例来源:origin: lealone/Lealone
@Override
public void closeChannel(SocketChannel channel) {
if (channel == null) {
return;
}
try {
InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.getRemoteAddress();
removeConnection(inetSocketAddress);
} catch (Exception e1) {
}
nioEventLoopAdapter.closeChannel(channel);
}
}
代码示例来源:origin: apache/kafka
public boolean finishConnect() throws IOException {
//we need to grab remoteAddr before finishConnect() is called otherwise
//it becomes inaccessible if the connection was refused.
SocketChannel socketChannel = transportLayer.socketChannel();
if (socketChannel != null) {
remoteAddress = socketChannel.getRemoteAddress();
}
boolean connected = transportLayer.finishConnect();
if (connected) {
if (ready()) {
state = ChannelState.READY;
} else if (remoteAddress != null) {
state = new ChannelState(ChannelState.State.AUTHENTICATE, remoteAddress.toString());
} else {
state = ChannelState.AUTHENTICATE;
}
}
return connected;
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public HandlerState call() throws Exception {
try {
switch (this.state) {
case CONNECTING:
connect();
break;
case WRITING:
write();
break;
case READING:
read();
break;
default:
throw new IllegalStateException("ProxySetupHandler should not be in state " + this.state);
}
} catch (IOException ioe) {
LOG.warn("Failed to establish a proxy connection for {}", this.client.getRemoteAddress(), ioe);
closeChannels();
}
return this.state;
}
代码示例来源:origin: apache/nifi
currentConnections.decrementAndGet();
logger.warn("Rejecting connection from {} because max connections has been met",
new Object[]{ socketChannel.getRemoteAddress().toString() });
IOUtils.closeQuietly(socketChannel);
continue;
new Object[]{socketChannel.getRemoteAddress().toString()});
代码示例来源:origin: wildfly/wildfly
public NioConnection(SocketChannel channel, NioBaseServer server) throws Exception {
this.channel=channel;
this.server=server;
setSocketParameters(this.channel.socket());
channel.configureBlocking(false);
this.connected=channel.isConnected();
send_buf=new Buffers(server.maxSendBuffers() *2); // space for actual bufs and length bufs!
this.peer_addr=server.usePeerConnections()? null /* read by first receive() */
: new IpAddress((InetSocketAddress)channel.getRemoteAddress());
last_access=getTimestamp(); // last time a message was sent or received (ns)
}
代码示例来源:origin: apache/nifi
final SocketAddress remoteSocketAddress = socketChannel.getRemoteAddress();
socketChannel.socket().setSoTimeout(socketReadTimeout);
socketChannel.socket().setReceiveBufferSize(receiveBufferSize);
代码示例来源:origin: wildfly/wildfly
hash = localAddress.hashCode();
final SocketAddress remoteAddress = accepted.getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
final InetSocketAddress address = (InetSocketAddress) remoteAddress;
代码示例来源:origin: wildfly/wildfly
hash = localAddress.hashCode();
final SocketAddress remoteAddress = accepted.getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
final InetSocketAddress address = (InetSocketAddress) remoteAddress;
代码示例来源:origin: apache/geode
private void createIoFilter(SocketChannel channel, boolean clientSocket) throws IOException {
if (getConduit().useSSL() && channel != null) {
InetSocketAddress address = (InetSocketAddress) channel.getRemoteAddress();
SSLEngine engine =
getConduit().getSocketCreator().createSSLEngine(address.getHostName(), address.getPort());
if (!clientSocket) {
engine.setWantClientAuth(true);
engine.setNeedClientAuth(true);
}
int packetBufferSize = engine.getSession().getPacketBufferSize();
if (inputBuffer == null
|| (inputBuffer.capacity() < packetBufferSize)) {
// TLS has a minimum input buffer size constraint
if (inputBuffer != null) {
Buffers.releaseReceiveBuffer(inputBuffer, getConduit().getStats());
}
inputBuffer = Buffers.acquireReceiveBuffer(packetBufferSize, getConduit().getStats());
}
if (channel.socket().getReceiveBufferSize() < packetBufferSize) {
channel.socket().setReceiveBufferSize(packetBufferSize);
}
if (channel.socket().getSendBufferSize() < packetBufferSize) {
channel.socket().setSendBufferSize(packetBufferSize);
}
ioFilter = getConduit().getSocketCreator().handshakeSSLSocketChannel(channel, engine,
getConduit().idleConnectionTimeout, clientSocket, inputBuffer, getConduit().getStats());
} else {
ioFilter = new NioPlainEngine();
}
}
代码示例来源:origin: wildfly/wildfly
short version=buf.getShort();
if(!Version.isBinaryCompatible(version))
throw new IOException("packet from " + channel.getRemoteAddress() + " has different version (" + Version.print(version) +
") from ours (" + Version.printVersion() + "); discarding it");
recv_buf.add(ByteBuffer.allocate(Global.SHORT_SIZE));
代码示例来源:origin: apache/cloudstack
final long timeTaken = System.currentTimeMillis() - startTimeMills;
if (timeTaken > 15000L) {
s_logger.warn("SSL Handshake has taken more than 15s to connect to: " + socketChannel.getRemoteAddress() +
". Please investigate this connection.");
return false;
代码示例来源:origin: apache/cloudstack
} catch (final SSLException sslException) {
s_logger.error(String.format("SSL error caught during wrap data: %s, for local address=%s, remote address=%s.",
sslException.getMessage(), socketChannel.getLocalAddress(), socketChannel.getRemoteAddress()));
sslEngine.closeOutbound();
return new HandshakeHolder(myAppData, myNetData, true);
代码示例来源:origin: apache/cloudstack
@Override
public void run() {
_selector.wakeup();
try {
sslEngine.beginHandshake();
if (!Link.doHandshake(socketChannel, sslEngine)) {
throw new IOException("SSL handshake timed out with " + socketChannel.getRemoteAddress());
}
if (s_logger.isTraceEnabled()) {
s_logger.trace("SSL: Handshake done");
}
final InetSocketAddress saddr = (InetSocketAddress)socket.getRemoteSocketAddress();
final Link link = new Link(saddr, nioConnection);
link.setSSLEngine(sslEngine);
link.setKey(socketChannel.register(key.selector(), SelectionKey.OP_READ, link));
final Task task = _factory.create(Task.Type.CONNECT, link, null);
registerLink(saddr, link);
_executor.submit(task);
} catch (IOException e) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Connection closed due to failure: " + e.getMessage());
}
closeAutoCloseable(socket, "accepting socket");
closeAutoCloseable(socketChannel, "accepting socketChannel");
} finally {
_selector.wakeup();
}
}
});
内容来源于网络,如有侵权,请联系作者删除!