本文整理了Java中java.nio.channels.SocketChannel.getLocalAddress()
方法的一些代码示例,展示了SocketChannel.getLocalAddress()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.getLocalAddress()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:getLocalAddress
暂无
代码示例来源:origin: wildfly/wildfly
@Override
public Address localAddress() {
InetSocketAddress local_addr=null;
if(channel != null) {
try {local_addr=(InetSocketAddress)channel.getLocalAddress();} catch(IOException e) {}
}
return local_addr != null? new IpAddress(local_addr) : null;
}
代码示例来源:origin: Netflix/EVCache
@Override
public String getSocketChannelLocalAddress() {
try {
if(getChannel() != null) {
return getChannel().getLocalAddress().toString();
}
} catch (IOException e) {
log.error("Exception", e);
}
return "NULL";
}
代码示例来源: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: apache/nifi
final SocketAddress localAddress = channel.getLocalAddress();
if (localAddress != null && localAddress instanceof InetSocketAddress) {
final InetSocketAddress inetSocketAddress = (InetSocketAddress) localAddress;
代码示例来源:origin: wildfly/wildfly
protected void connect(Address dest, boolean send_local_addr) throws Exception {
SocketAddress destAddr=new InetSocketAddress(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort());
try {
if(!server.deferClientBinding())
this.channel.bind(new InetSocketAddress(server.clientBindAddress(), server.clientBindPort()));
this.key=server.register(channel, SelectionKey.OP_CONNECT | SelectionKey.OP_READ, this);
if(Util.connect(channel, destAddr) && channel.finishConnect()) {
clearSelectionKey(SelectionKey.OP_CONNECT);
this.connected=channel.isConnected();
}
if(this.channel.getLocalAddress() != null && this.channel.getLocalAddress().equals(destAddr))
throw new IllegalStateException("socket's bind and connect address are the same: " + destAddr);
if(send_local_addr)
sendLocalAddress(server.localAddress());
}
catch(Exception t) {
close();
throw t;
}
}
代码示例来源:origin: wildfly/wildfly
accepted = channel.accept();
if (accepted != null) try {
final SocketAddress localAddress = accepted.getLocalAddress();
int hash;
if (localAddress instanceof InetSocketAddress) {
代码示例来源:origin: wildfly/wildfly
boolean ok = false;
if (accepted != null) try {
final SocketAddress localAddress = accepted.getLocalAddress();
int hash;
if (localAddress instanceof InetSocketAddress) {
代码示例来源: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
} catch (final SSLException sslException) {
s_logger.error(String.format("SSL error caught during unwrap data: %s, for local address=%s, remote address=%s. The client may have invalid ca-certificates.",
sslException.getMessage(), socketChannel.getLocalAddress(), socketChannel.getRemoteAddress()));
sslEngine.closeOutbound();
return new HandshakeHolder(peerAppData, peerNetData, false);
代码示例来源:origin: jitsi/ice4j
/**
* {@inheritDoc}
*
* Forwards to {@link #delegate}.
*/
@Override
public SocketAddress getLocalAddress()
throws IOException
{
return delegate.getLocalAddress();
}
代码示例来源:origin: org.mycore/selenium-utils
public static InetAddress getLocalAdress(String remoteHost, int port) throws IOException {
InetSocketAddress socketAddr = new InetSocketAddress(remoteHost, port);
SocketChannel socketChannel = SocketChannel.open(socketAddr);
InetSocketAddress localAddress = (InetSocketAddress) socketChannel.getLocalAddress();
return localAddress.getAddress();
}
}
代码示例来源:origin: apache/activemq-artemis
@Override
public Address localAddress() {
InetSocketAddress local_addr=null;
if(channel != null) {
try {local_addr=(InetSocketAddress)channel.getLocalAddress();} catch(IOException e) {}
}
return local_addr != null? new IpAddress(local_addr) : null;
}
代码示例来源:origin: apache/activemq-artemis
@Override
public Address localAddress() {
InetSocketAddress local_addr=null;
if(channel != null) {
try {local_addr=(InetSocketAddress)channel.getLocalAddress();} catch(IOException e) {}
}
return local_addr != null? new IpAddress(local_addr) : null;
}
代码示例来源:origin: net.openhft/chronicle-core
@Override
public InetSocketAddress getLocalAddress() throws IORuntimeException {
try {
return (InetSocketAddress) socketChannel.getLocalAddress();
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
代码示例来源:origin: OpenHFT/Chronicle-Core
@Override
public InetSocketAddress getLocalAddress() throws IORuntimeException {
try {
return (InetSocketAddress) socketChannel.getLocalAddress();
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
代码示例来源:origin: org.apache.activemq/artemis-jms-client-all
@Override
public Address localAddress() {
InetSocketAddress local_addr=null;
if(channel != null) {
try {local_addr=(InetSocketAddress)channel.getLocalAddress();} catch(IOException e) {}
}
return local_addr != null? new IpAddress(local_addr) : null;
}
代码示例来源:origin: apache/activemq-artemis
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: apache/activemq-artemis
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: org.apache.activemq/artemis-jms-client-all
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: apache/asterixdb
private String getConnectionInfo() {
try {
return getSocketChannel().getLocalAddress() + " -> " + getSocketChannel().getRemoteAddress();
} catch (IOException e) {
LOGGER.warn("failed to get connection info", e);
return "";
}
}
内容来源于网络,如有侵权,请联系作者删除!