Exemplo n.º 1
0
  private void setSocketParameters(Socket client_sock) throws SocketException {
    if (log.isTraceEnabled())
      log.trace(
          "["
              + local_addr
              + "] accepted connection from "
              + client_sock.getInetAddress()
              + ":"
              + client_sock.getPort());
    try {
      client_sock.setSendBufferSize(send_buf_size);
    } catch (IllegalArgumentException ex) {
      if (log.isErrorEnabled())
        log.error("exception setting send buffer size to " + send_buf_size + " bytes", ex);
    }
    try {
      client_sock.setReceiveBufferSize(recv_buf_size);
    } catch (IllegalArgumentException ex) {
      if (log.isErrorEnabled())
        log.error("exception setting receive buffer size to " + send_buf_size + " bytes", ex);
    }

    client_sock.setKeepAlive(true);
    client_sock.setTcpNoDelay(tcp_nodelay);
    if (linger > 0) client_sock.setSoLinger(true, linger);
    else client_sock.setSoLinger(false, -1);
  }
Exemplo n.º 2
0
  /**
   * Applies the current settings to the given socket.
   *
   * @param s Socket to apply the settings to
   * @return Socket the input socket
   */
  protected Socket applySettings(Socket s) {
    try {
      s.setKeepAlive(SO_KEEPALIVE);
      s.setOOBInline(OOBINLINE);
      s.setReuseAddress(SO_REUSEADDR);
      s.setTcpNoDelay(TCP_NODELAY);
      s.setOOBInline(OOBINLINE);

      s.setReceiveBufferSize(SO_RCVBUF);
      s.setSendBufferSize(SO_SNDBUF);
      s.setSoTimeout(SO_TIMEOUT);
      s.setSoLinger(SO_LINGER, LINGER);
    } catch (SocketException e) {
      throw new RuntimeException(e);
    }
    return s;
  }
Exemplo n.º 3
0
  protected void setSocketParameters(Socket client_sock) throws SocketException {
    try {
      client_sock.setSendBufferSize(server.send_buf_size);
    } catch (IllegalArgumentException ex) {
      server.log.error(
          "%s: exception setting send buffer to %d bytes: %s",
          server.local_addr, server.send_buf_size, ex);
    }
    try {
      client_sock.setReceiveBufferSize(server.recv_buf_size);
    } catch (IllegalArgumentException ex) {
      server.log.error(
          "%s: exception setting receive buffer to %d bytes: %s",
          server.local_addr, server.recv_buf_size, ex);
    }

    client_sock.setKeepAlive(true);
    client_sock.setTcpNoDelay(server.tcp_nodelay);
    if (server.linger > 0) client_sock.setSoLinger(true, server.linger);
    else client_sock.setSoLinger(false, -1);
  }
 private Socket connect() {
   Socket socket = null;
   int attempts = 0;
   do {
     attempts++;
     try {
       socket = new Socket(Utils.REGISTRAR_ADDR, Utils.REGISTRAR_PORT);
       socket.setKeepAlive(true);
       socket.setSoTimeout(0);
     } catch (Exception e) {
       String msg =
           String.format("Warning: connection attempt %d failed at %s.", attempts, this.getInfo());
       System.err.println(msg);
       System.err.println(e.getMessage());
       try {
         Thread.sleep(random.nextInt(100) + 1); /* [0..100] + 1 > 0. */
       } catch (InterruptedException ignored) {
       }
     }
   } while (socket == null);
   return socket;
 }
Exemplo n.º 5
0
 public void setKeepAlive(boolean on) throws SocketException {
   mSocket.setKeepAlive(on);
 }