java.net.Socket.getLocalSocketAddress()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(477)

本文整理了Java中java.net.Socket.getLocalSocketAddress()方法的一些代码示例,展示了Socket.getLocalSocketAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.getLocalSocketAddress()方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:getLocalSocketAddress

Socket.getLocalSocketAddress介绍

[英]Returns the local address and port of this socket as a SocketAddress or null if the socket is unbound. This is useful on multihomed hosts.
[中]将此套接字的本地地址和端口作为SocketAddress返回,如果套接字未绑定,则返回null。这在多宿主主机上很有用。

代码示例

代码示例来源:origin: netty/netty

@Override
protected SocketAddress localAddress0() {
  return socket.getLocalSocketAddress();
}

代码示例来源:origin: alibaba/canal

public SocketAddress getLocalSocketAddress() {
  Socket socket = this.socket;
  if (socket != null) {
    return socket.getLocalSocketAddress();
  }
  return null;
}

代码示例来源:origin: redisson/redisson

@Override
protected SocketAddress localAddress0() {
  return socket.getLocalSocketAddress();
}

代码示例来源:origin: TooTallNate/Java-WebSocket

@Override
public InetSocketAddress getLocalSocketAddress( WebSocket conn ) {
  if( socket != null )
    return (InetSocketAddress) socket.getLocalSocketAddress();
  return null;
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public SocketAddress getLocalSocketAddress() {
  return sock.getLocalSocketAddress();
}

代码示例来源:origin: wildfly/wildfly

@Override
protected SocketAddress localAddress0() {
  return socket.getLocalSocketAddress();
}

代码示例来源:origin: io.netty/netty

@Override
InetSocketAddress getLocalSocketAddress() throws Exception {
  return (InetSocketAddress) socket.getLocalSocketAddress();
}

代码示例来源:origin: apache/zookeeper

private void updateSocketAddresses() {
  Socket socket = ((SocketChannel) sockKey.channel()).socket();
  localSocketAddress = socket.getLocalSocketAddress();
  remoteSocketAddress = socket.getRemoteSocketAddress();
}

代码示例来源:origin: netty/netty

@Override
protected SocketAddress localAddress0() {
  return javaChannel().socket().getLocalSocketAddress();
}

代码示例来源:origin: wildfly/wildfly

public String toString() {
  return String.format("%s -> %s", sock.getLocalSocketAddress(), peer_addr);
}

代码示例来源:origin: io.netty/netty

@Override
InetSocketAddress getLocalSocketAddress() throws Exception {
  return (InetSocketAddress) channel.socket().getLocalSocketAddress();
}

代码示例来源:origin: redisson/redisson

@Override
protected SocketAddress localAddress0() {
  return javaChannel().socket().getLocalSocketAddress();
}

代码示例来源:origin: apache/zookeeper

/**
 * See {@link Socket#getLocalSocketAddress()}. Calling this method does not trigger mode detection.
 */
@Override
public SocketAddress getLocalSocketAddress() {
  return getSocketAllowUnknownMode().getLocalSocketAddress();
}

代码示例来源:origin: TooTallNate/Java-WebSocket

@Override
public InetSocketAddress getLocalSocketAddress( WebSocket conn ) {
  return (InetSocketAddress) getSocket( conn ).getLocalSocketAddress();
}

代码示例来源:origin: wildfly/wildfly

public Address localAddress() {
  InetSocketAddress local_addr=sock != null? (InetSocketAddress)sock.getLocalSocketAddress() : null;
  return local_addr != null? new IpAddress(local_addr) : null;
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public SocketAddress localAddress() {
  return socketChannel().socket().getLocalSocketAddress();
}

代码示例来源:origin: wildfly/wildfly

@Override
protected SocketAddress localAddress0() {
  return javaChannel().socket().getLocalSocketAddress();
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public SocketAddress localAddress() {
  return socketChannel().socket().getLocalSocketAddress();
}

代码示例来源: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.defer_client_binding)
      this.sock.bind(new InetSocketAddress(server.client_bind_addr, server.client_bind_port));
    Util.connect(this.sock, destAddr, server.sock_conn_timeout);
    if(this.sock.getLocalSocketAddress() != null && this.sock.getLocalSocketAddress().equals(destAddr))
      throw new IllegalStateException("socket's bind and connect address are the same: " + destAddr);
    this.out=new DataOutputStream(createBufferedOutputStream(sock.getOutputStream()));
    this.in=new DataInputStream(createBufferedInputStream(sock.getInputStream()));
    connected=sock.isConnected();
    if(send_local_addr)
      sendLocalAddress(server.localAddress());
  }
  catch(Exception t) {
    Util.close(this.sock);
    connected=false;
    throw t;
  }
}

代码示例来源:origin: oldmanpushcart/greys-anatomy

private String sessionToString(Session session) {
  return new TTable(new TTable.ColumnDefine[]{
      new TTable.ColumnDefine(TTable.Align.RIGHT),
      new TTable.ColumnDefine(TTable.Align.LEFT)
  })
      .addRow("JAVA_PID", session.getJavaPid())
      .addRow("SESSION_ID", session.getSessionId())
      .addRow("DURATION", session.getSessionDuration())
      .addRow("SILENT", session.isSilent())
      .addRow("CHARSET", session.getCharset())
      .addRow("PROMPT", session.getPrompt())
      .addRow("FROM", session.getSocketChannel().socket().getRemoteSocketAddress())
      .addRow("TO", session.getSocketChannel().socket().getLocalSocketAddress())
      .padding(1)
      .rendering();
}

相关文章