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

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

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

Socket.isBound介绍

[英]Returns whether this socket is bound to a local address and port.
[中]返回此套接字是否绑定到本地地址和端口。

代码示例

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

@Override
public boolean isBound() {
  return sock.isBound();
}

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

@Override
boolean isSocketBound() {
  return socket.isBound();
}

代码示例来源:origin: stackoverflow.com

Socket s = new Socket();

System.out.println("isConnected: " + s.isConnected() +
         " isBound: "     + s.isBound() +
         " isClosed: "    + s.isClosed());

s.connect(new InetSocketAddress("google.com", 80));

System.out.println("isConnected: " + s.isConnected() +
          " isBound: "    + s.isBound() +
          " isClosed: "   + s.isClosed());

s.close();

System.out.println("isConnected: " + s.isConnected() +
          " isBound: "    + s.isBound() +
          " isClosed: "   + s.isClosed());

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

/**
 * 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.
 */
public SocketAddress getLocalSocketAddress() {
  if (!isBound()) {
    return null;
  }
  return new InetSocketAddress(getLocalAddress(), getLocalPort());
}

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

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

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

/**
 * Returns the local port this socket is bound to, or -1 if the socket is unbound.
 */
public int getLocalPort() {
  if (!isBound()) {
    return -1;
  }
  return impl.getLocalPort();
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory isBound(Environment env, Memory... args) {
  return socket.isBound() ? Memory.TRUE : Memory.FALSE;
}

代码示例来源:origin: sohutv/cachecloud

public boolean isConnected() {
 return socket != null && socket.isBound() && !socket.isClosed() && socket.isConnected()
   && !socket.isInputShutdown() && !socket.isOutputShutdown();
}

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

public boolean isValid() {
  if(isClosed())
    return false;
  Socket s = socketChannel.socket();
  boolean isValidSocket = !s.isClosed() && s.isBound() && s.isConnected();
  if(!isValidSocket) {
    return false;
  }
  if (isIdleConnectionTimeoutExceeded()) {
    return false;
  }
  return true;
}

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

if (!socket.isBound()) {
  log.error("Socket is not bound [{}]", address);
  return false;

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

@Override
  public boolean hasExpired(SlotInfo<? extends SocketPoolable> info) throws Exception {
    Socket socket = info.getPoolable().getSocket();
    try {
      return socket == null
          || !socket.isConnected()
          || !socket.isBound()
          || socket.isClosed()
          || socket.isInputShutdown()
          || socket.isOutputShutdown();
    } catch (Exception e) {
      log.warn("Socket {} is expired", socket, e);
      return true;
    }
  }
}

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

socket.setReuseAddress( isReuseAddr() );
if( !socket.isBound() ) {
  socket.connect( new InetSocketAddress( uri.getHost(), getPort() ), connectTimeout );

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

@Override
public void connect(SocketAddress remoteAddr, int timeout) throws IOException {
  if (!channel.isBlocking()) {
    throw new IllegalBlockingModeException();
  }
  if (isConnected()) {
    throw new AlreadyConnectedException();
  }
  super.connect(remoteAddr, timeout);
  channel.initLocalAddressAndPort();
  if (super.isConnected()) {
    channel.setConnected();
    channel.isBound = super.isBound();
  }
}

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

if (isBound()) {
  throw new BindException("Socket is already bound");

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

synchronized (connectLock) {
  try {
    if (!isBound()) {

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

boolean isValid = !s.isClosed() && s.isBound() && s.isConnected();
if(!isValid && logger.isDebugEnabled())
  logger.debug("Socket connection " + sands + " is no longer valid, closing.");

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

@Test
public void testRepeatedClosedConnections() throws Exception {
  for(int i = 0; i < 100; i++) {
    Socket s = new Socket();
    s.setTcpNoDelay(true);
    s.setSoTimeout(1000);
    s.connect(new InetSocketAddress("localhost", socketPort));
    logger.info("Client opened" + i);
    // Thread.sleep(1);
    assertTrue(s.isConnected());
    assertTrue(s.isBound());
    assertTrue(!s.isClosed());
    s.close();
    logger.info("Client closed" + i);
  }
}

代码示例来源:origin: stackoverflow.com

return delegate.isBound();

代码示例来源:origin: stackoverflow.com

return delegate.isBound();

代码示例来源:origin: stackoverflow.com

return delegate.isBound();

相关文章