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

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

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

Socket.getKeepAlive介绍

[英]Returns this socket's SocketOptions#SO_KEEPALIVE setting.
[中]返回此套接字的SocketOptions#SO_KEEPALIVE设置。

代码示例

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

@Override
public boolean getKeepAlive() throws SocketException {
  return sock.getKeepAlive();
}

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

@Override
public boolean isKeepAlive() {
  try {
    return javaSocket.getKeepAlive();
  } catch (SocketException e) {
    throw new ChannelException(e);
  }
}

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

@Override
public boolean isKeepAlive() {
  try {
    return javaSocket.getKeepAlive();
  } catch (SocketException e) {
    throw new ChannelException(e);
  }
}

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

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

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

@Override
public boolean isKeepAlive() {
  try {
    return javaSocket.getKeepAlive();
  } catch (SocketException e) {
    throw new ChannelException(e);
  }
}

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

public boolean isKeepAlive() {
  try {
    return socket.getKeepAlive();
  } catch (SocketException e) {
    throw new ChannelException(e);
  }
}

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

public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.CLOSE_ABORT) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getSoLinger() == 0));
  } else if (option == Options.IP_TRAFFIC_CLASS) {
    return option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getTrafficClass()));
  } else if (option == Options.KEEP_ALIVE) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getKeepAlive()));
  } else if (option == Options.READ_TIMEOUT) {
    return option.cast(Integer.valueOf(conduit.getReadTimeout()));
  } else if (option == Options.RECEIVE_BUFFER) {
    return option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getReceiveBufferSize()));
  } else if (option == Options.SEND_BUFFER) {
    return option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getSendBufferSize()));
  } else if (option == Options.TCP_NODELAY) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getTcpNoDelay()));
  } else if (option == Options.TCP_OOB_INLINE) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getOOBInline()));
  } else if (option == Options.WRITE_TIMEOUT) {
    return option.cast(Integer.valueOf(conduit.getWriteTimeout()));
  } else {
    return null;
  }
}

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

conduit.getSocketChannel().socket().setTrafficClass(Options.IP_TRAFFIC_CLASS.cast(value).intValue());
} else if (option == Options.KEEP_ALIVE) {
  result = option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getKeepAlive()));
  conduit.getSocketChannel().socket().setKeepAlive(Options.KEEP_ALIVE.cast(value, Boolean.FALSE).booleanValue());
} else if (option == Options.READ_TIMEOUT) {

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

@Override
  public void run() {
    try {
      byte[] buf = new byte[1024];
      int bytesRead = unifiedSocket.getInputStream().read(buf, 0, 1024);
      // Make sure the settings applied above before the socket was potentially upgraded to
      // TLS still apply.
      Assert.assertEquals(tcpNoDelay, unifiedSocket.getTcpNoDelay());
      Assert.assertEquals(TIMEOUT, unifiedSocket.getSoTimeout());
      Assert.assertEquals(keepAlive, unifiedSocket.getKeepAlive());
      if (bytesRead > 0) {
        byte[] dataFromClient = new byte[bytesRead];
        System.arraycopy(buf, 0, dataFromClient, 0, bytesRead);
        synchronized (dataFromClients) {
          dataFromClients.add(dataFromClient);
        }
      }
      unifiedSocket.getOutputStream().write(dataToClient);
      unifiedSocket.getOutputStream().flush();
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      forceClose(unifiedSocket);
    }
  }
});

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

@Nullable @Override public Object call() throws Exception {
    Socket sock = null;
    try {
      sock = new Socket(addr, 60000);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
      sock.setKeepAlive(true);
      sock.setSoTimeout(2000);
      sock.setSendBufferSize(256 * 1024);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
      int i = 0;
      while (!done.get()) {
        sock.getOutputStream().write(++i);
        sock.getOutputStream().flush();
        X.println("Wrote to socket: " + i);
        X.println("Socket connected: " + sock.isConnected());
        X.println("Socket keep alive: " + sock.getKeepAlive());
        U.sleep(1000);
      }
      return null;
    }
    finally {
      U.closeQuiet(sock);
    }
  }
},

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

return delegate.getKeepAlive();

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

return delegate.getKeepAlive();

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

return delegate.getKeepAlive();

代码示例来源:origin: commons-net/commons-net

/**
 * Returns the current value of the SO_KEEPALIVE flag on the currently opened socket.
 * Delegates to {@link Socket#getKeepAlive()}
 * @return True if SO_KEEPALIVE is enabled.
 * @throws SocketException if there is a problem with the socket
 * @throws NullPointerException if the socket is not currently open
 * @since 2.2
 */
public boolean getKeepAlive() throws SocketException {
  return _socket_.getKeepAlive();
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public boolean getKeepAlive() throws SocketException {
  return socket.getKeepAlive();
}

代码示例来源:origin: com.sun.mail/javax.mail

@Override
public boolean getKeepAlive() throws SocketException {
  return socket.getKeepAlive();
}

代码示例来源:origin: spring-projects/spring-integration

public boolean getKeepAlive() throws SocketException {
  return this.socket.getKeepAlive();
}

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

/**
 * {@inheritDoc}
 */
@Override
public Boolean isKeepAlive() {
  try {
    return socket.getKeepAlive();
  } catch (SocketException e) {
    throw new ConfigurationException(e);
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

Assert.assertEquals(54321, socketOptions.getSoTimeout().intValue());
Assert.assertEquals(false, socket.getKeepAlive());
Assert.assertEquals(false, socket.getReuseAddress());
Assert.assertEquals(false, socket.getTcpNoDelay());

代码示例来源:origin: org.apache.logging.log4j/log4j-core

Assert.assertEquals(54321, socketOptions.getSoTimeout().intValue());
Assert.assertEquals(false, socket.getKeepAlive());
Assert.assertEquals(false, socket.getOOBInline());
Assert.assertEquals(false, socket.getReuseAddress());

相关文章

微信公众号

最新文章

更多