Tabnine Logo
ConnectException
Code IndexAdd Tabnine to your IDE (free)

How to use
ConnectException
in
java.net

Best Java code snippets using java.net.ConnectException (Showing top 20 results out of 2,853)

Refine searchRefine arrow

  • Socket
  • InetSocketAddress
  • AlreadyConnectedException
  • ConnectionPendingException
  • CompletableFuture
origin: apache/geode

this.preserveOrder = preserveOrder;
setRemoteAddr(remoteAddr);
this.conduitIdStr = this.owner.getConduit().getSocketId().toString();
this.handshakeRead = false;
this.handshakeCancelled = false;
  new InetSocketAddress(remoteAddr.getInetAddress(), remoteAddr.getDirectChannelPort());
SocketChannel channel = SocketChannel.open();
this.owner.addConnectingSocket(channel.socket(), addr.getAddress());
 channel.socket().setTcpNoDelay(true);
 channel.socket().setKeepAlive(SocketCreator.ENABLE_TCP_KEEP_ALIVE);
  channel.socket().connect(addr, connectTime);
  ConnectException c = new ConnectException("Encountered bug #45044 - retrying");
  c.initCause(e);
  ConnectException c = new ConnectException("Problem connecting to peer " + addr);
  c.initCause(e);
  throw c;
 } catch (CancelledKeyException | ClosedSelectorException e) {
  ConnectException c = new ConnectException(
    String.format("Attempt timed out after %s milliseconds",
      connectTime));
  c.initCause(e);
  throw c;
origin: apache/zeppelin

public static boolean checkIfRemoteEndpointAccessible(String host, int port) {
 try {
  Socket discover = new Socket();
  discover.setSoTimeout(1000);
  discover.connect(new InetSocketAddress(host, port), 1000);
  discover.close();
  return true;
 } catch (ConnectException cne) {
  // end point is not accessible
  if (LOGGER.isDebugEnabled()) {
   LOGGER.debug("Remote endpoint '" + host + ":" + port + "' is not accessible " +
     "(might be initializing): " + cne.getMessage());
  }
  return false;
 } catch (IOException ioe) {
  // end point is not accessible
  if (LOGGER.isDebugEnabled()) {
   LOGGER.debug("Remote endpoint '" + host + ":" + port + "' is not accessible " +
     "(might be initializing): " + ioe.getMessage());
  }
  return false;
 }
}
origin: io.netty/netty

private static void connect(SelectionKey k) throws IOException {
  NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment();
  try {
    if (ch.channel.finishConnect()) {
      k.cancel();
      if (ch.timoutTimer != null) {
        ch.timoutTimer.cancel();
      }
      ch.worker.register(ch, ch.connectFuture);
    }
  } catch (ConnectException e) {
    ConnectException newE = new ConnectException(e.getMessage() + ": " + ch.requestedRemoteAddress);
    newE.setStackTrace(e.getStackTrace());
    throw newE;
  }
}
origin: netty/netty

AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
  super(exception.getMessage() + ": " + remoteAddress);
  initCause(exception);
  setStackTrace(exception.getStackTrace());
}
origin: redisson/redisson

final boolean failConnectPromise(Throwable cause) {
  if (connectPromise != null) {
    // SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was
    // not set before calling connect. This means finishConnect will not detect any error and would
    // successfully complete the connectPromise and update the channel state to active (which is incorrect).
    ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise;
    AbstractKQueueChannel.this.connectPromise = null;
    if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause
            : new ConnectException("failed to connect").initCause(cause))) {
      closeIfClosed();
      return true;
    }
  }
  return false;
}
origin: k9mail/k-9

private void handleConnectException(ConnectException e) throws ConnectException {
  String message = e.getMessage();
  String[] tokens = message.split("-");
  if (tokens.length > 1 && tokens[1] != null) {
    Timber.e(e, "Stripping host/port from ConnectionException for %s", getLogId());
    throw new ConnectException(tokens[1].trim());
  } else {
    throw e;
  }
}
origin: jmxtrans/jmxtrans-agent

private void ensureGraphiteConnection() throws IOException {
  boolean socketIsValid;
  try {
    socketIsValid = socket != null &&
        socket.isConnected()
        && socket.isBound()
        && !socket.isClosed()
        && !socket.isInputShutdown()
        && !socket.isOutputShutdown();
  } catch (Exception e) {
    socketIsValid = false;
  }
  if (!socketIsValid) {
    writer = null;
    try {
      socket = new Socket();
      socket.setKeepAlive(true);
      socket.connect(
          new InetSocketAddress(graphiteServerHostAndPort.getHost(), graphiteServerHostAndPort.getPort()),
          socketConnectTimeoutInMillis);
    } catch (IOException e) {
      ConnectException ce = new ConnectException("Exception connecting to " + graphiteServerHostAndPort);
      ce.initCause(e);
      throw ce;
    }
  }
  if (writer == null) {
    writer = new OutputStreamWriter(socket.getOutputStream(), UTF_8);
  }
}
origin: org.jppf/jppf-common

/**
 * Open the underlying socket connection.
 * @throws ConnectException if the socket fails to connect.
 * @throws IOException if the underlying input and output streams raise an error.
 */
@Override
public final void open() throws ConnectException, IOException {
 if (!opened) {
  if ((host == null) || "".equals(host.trim())) throw new ConnectException("You must specify the host name");
  else if (port <= 0) throw new ConnectException("You must specify the port number");
  socket = new Socket();
  final InetSocketAddress addr = new InetSocketAddress(host, port);
  socket.setReceiveBufferSize(IO.SOCKET_BUFFER_SIZE);
  socket.setSendBufferSize(IO.SOCKET_BUFFER_SIZE);
  socket.setTcpNoDelay(IO.SOCKET_TCP_NODELAY);
  socket.setKeepAlive(IO.SOCKET_KEEPALIVE);
  socket.connect(addr);
  initStreams();
  opened = true;
  if (log.isDebugEnabled()) log.debug("getReceiveBufferSize() = " + socket.getReceiveBufferSize());
 }
 //else throw new ConnectException("Client connection already opened");
}
origin: OpenNMS/opennms

  m_socket = new Socket();
  m_socket.setTcpNoDelay(true);
  m_socket.connect(new InetSocketAddress(getAddress(), getPort()), getTimeout());
  m_socket.setSoTimeout(getTimeout());
  disconnect();
} catch (final ConnectException e) {
  LOG.debug("connection failed: {}", e.getMessage());
  setError(e);
  disconnect();
origin: org.apache.hadoop/hadoop-common-test

socket.bind(new InetSocketAddress("127.0.0.1", 0));
System.err.println("local address: " + socket.getLocalAddress());
System.err.println("local port: " + socket.getLocalPort());
try {
 NetUtils.connect(socket,
  new InetSocketAddress(socket.getLocalAddress(), socket.getLocalPort()),
  20000);
 socket.close();
} catch (ConnectException ce) {
 System.err.println("Got exception: " + ce);
 assertTrue(ce.getMessage().contains("resulted in a loopback"));
} catch (SocketException se) {
origin: com.sun.mail/javax.mail

    host + ":" + port);
if (cto >= 0)
  socket.connect(new InetSocketAddress(proxyHost, proxyPort), cto);
else
  socket.connect(new InetSocketAddress(proxyHost, proxyPort));
PrintStream os = new PrintStream(socket.getOutputStream(), false,
          StandardCharsets.UTF_8.name());
StringBuilder requestBuilder = new StringBuilder();
    ConnectException ex = new ConnectException(
    "connection through proxy " +
    proxyHost + ":" + proxyPort + " to " +
origin: net.sf.jdos/jdos-client

public static ArrayList<Service> getServices(InetAddress host,int port, String serviceGroup) throws ConnectException {
  ArrayList<Service>  result=new ArrayList<Service> ();
  Socket s=createSocket(host, port, 5, 1000);
  if (s==null) throw new ConnectException("Could not connect to host "+host+" at port "+ port);
  BufferedReader is;
  try {
    is = new BufferedReader(new InputStreamReader(s.getInputStream()));
    BufferedWriter os=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));		
    os.write(new QueryGroupServicesImpl(serviceGroup).toString()+"\n");	
    String lineread=null;
    do {
      lineread=is.readLine();
      if (lineread!=null && !lineread.isEmpty()){
        Service serv=ServiceImpl.fromString(lineread);
        result.add(serv);               
      }
    } while (lineread!=null && !lineread.isEmpty());
    s.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
  Logger.getLogger(RemoteSocketClient.class.getName()).log(Level.SEVERE, null, "finished  queryallservices");
  return result;
}

origin: org.jitsi/jain-sip-ri-ossonly

public Socket createSocket(InetAddress address, int port,
    InetAddress myAddress) throws IOException {
  if (myAddress != null) {
    Socket sock = new Socket();
    // http://java.net/jira/browse/JSIP-440 trying to bind to the correct ipaddress (in case of multiple vip addresses by example)
    // and let the JDK pick an ephemeral port
    sock.bind(new InetSocketAddress(myAddress, 0));
    try {
      sock.connect(new InetSocketAddress(address, port), 8000);
    } catch (SocketTimeoutException e) {
      throw new ConnectException("Socket timeout error (8sec)" + address + ":" + port);
    }
    return sock;
  }
  else {
    Socket sock =  new Socket();
    try {
      sock.connect(new InetSocketAddress(address, port), 8000);
    } catch (SocketTimeoutException e) {
      throw new ConnectException("Socket timeout error (8sec)" + address + ":" + port);
    }
    return sock;
  }
}
origin: org.apache.hadoop/hadoop-common

SocketChannel ch = socket.getChannel();
   "Local address %s must be of same family as remote address %s.",
   localAddr, endpoint);
 socket.bind(localAddr);
 if (ch == null) {
  socket.connect(endpoint, timeout);
 } else {
  SocketIOWithTimeout.connect(ch, endpoint, timeout);
 LOG.info("Detected a loopback TCP socket, disconnecting it");
 socket.close();
 throw new ConnectException(
  "Localhost targeted connection resulted in a loopback. " +
  "No daemon is listening on the target port.");
origin: org.sonatype.sisu/sisu-jsw-utils

private void ping()
{
  try
  {
    log.debug( "Pinging on port {} ...", port );
    socket = new Socket();
    socket.connect( new InetSocketAddress( LOCALHOST, port ), timeout );
  }
  catch ( ConnectException e )
  {
    // TODO this check is quite a hack. we need a better way to determine that connection was refused
    if ( "Connection refused".equals( e.getMessage() ) )
    {
      running = false;
      shutdownJSW();
    }
  }
  catch ( IOException e )
  {
    // log.debug( "Skipped {}:{}", e.getClass().getName(), e.getMessage() );
  }
  finally
  {
    close( socket );
  }
}
origin: stackoverflow.com

 socketConnection = null;

for(InetAddress addr : InetAddress.getAllByName(server))
{
  if (addr instanceof Inet4Address)
  {
    socketConnection = new Socket();
    try {
      socketConnection.connect(new InetSocketAddress(addr, port));
      break;
    }
    catch (IOException e) {
      socketConnection = null;
    }
  }
}

if (socketConnection == null) {
  throw new ConnectException("Cannot connect to '" + host + "' using IPv4");
}
origin: square/okhttp

/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void connectSocket(int connectTimeout, int readTimeout, Call call,
  EventListener eventListener) throws IOException {
 Proxy proxy = route.proxy();
 Address address = route.address();
 rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
   ? address.socketFactory().createSocket()
   : new Socket(proxy);
 eventListener.connectStart(call, route.socketAddress(), proxy);
 rawSocket.setSoTimeout(readTimeout);
 try {
  Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
 } catch (ConnectException e) {
  ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
  ce.initCause(e);
  throw ce;
 }
 // The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0
 // More details:
 // https://github.com/square/okhttp/issues/3245
 // https://android-review.googlesource.com/#/c/271775/
 try {
  source = Okio.buffer(Okio.source(rawSocket));
  sink = Okio.buffer(Okio.sink(rawSocket));
 } catch (NullPointerException npe) {
  if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) {
   throw new IOException(npe);
  }
 }
}
origin: io.netty/netty

channel.socket.connect(
    remoteAddress, channel.getConfig().getConnectTimeoutMillis());
connected = true;
channel.in = new PushbackInputStream(channel.socket.getInputStream(), 1);
channel.out = channel.socket.getOutputStream();
if (t instanceof ConnectException) {
  if (t instanceof ConnectException) {
    Throwable newT = new ConnectException(t.getMessage() + ": " + remoteAddress);
    newT.setStackTrace(t.getStackTrace());
    t = newT;
origin: org.gradle/gradle-messaging

private SocketChannel tryConnect(InetEndpoint address, InetAddress candidate) throws IOException {
  SocketChannel socketChannel = SocketChannel.open();
  try {
    socketChannel.socket().connect(new InetSocketAddress(candidate, address.getPort()), CONNECT_TIMEOUT);
    if (!detectSelfConnect(socketChannel)) {
      return socketChannel;
    }
    socketChannel.close();
  } catch (IOException e) {
    socketChannel.close();
    throw e;
  } catch (Throwable e) {
    socketChannel.close();
    throw UncheckedException.throwAsUncheckedException(e);
  }
  throw new java.net.ConnectException(String.format("Socket connected to itself on %s port %s.", candidate, address.getPort()));
}
origin: timewalker74/ffmq

socket.connect(new InetSocketAddress(host,port),connectTimeout*1000);
log.error("#"+id+" could not connect to "+host+":"+port+" (timeout="+connectTimeout+"s) : "+e.getMessage());
throw new PacketTransportException("Could not connect to "+host+":"+port+" : "+e.toString());
java.netConnectException

Javadoc

A ConnectException is thrown if a connection cannot be established to a remote host on a specific port.

Most applications should not catch this exception; it is more robust to catch the superclass SocketException.

Most used methods

  • <init>
    Constructs a new instance with the given detail message and cause.
  • getMessage
  • initCause
  • getStackTrace
  • toString
  • printStackTrace
  • setStackTrace
  • fillInStackTrace
  • getLocalizedMessage
  • getCause

Popular in Java

  • Making http post requests using okhttp
  • onCreateOptionsMenu (Activity)
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now