Example usage for java.net Socket close

List of usage examples for java.net Socket close

Introduction

In this page you can find the example usage for java.net Socket close.

Prototype

public synchronized void close() throws IOException 

Source Link

Document

Closes this socket.

Usage

From source file:Main.java

public static void closeQuietly(Socket socket) {
    if (socket == null)
        return;//from   w  w w.j av a 2 s .c om
    try {
        socket.close();
    } catch (IOException e) {
        //just ignore
    }
}

From source file:Main.java

public static void closeQuietly(Socket paramSocket) {
    if (paramSocket != null)
        ;//from w w  w .j  a v  a  2 s  . c  o m
    try {
        paramSocket.close();
        return;
    } catch (Exception localException) {
    }
}

From source file:Main.java

public static final void close(Socket closeable) {
    if (closeable != null) {
        try {//from   www  . ja  v  a2s. c  om
            closeable.close();
        } catch (IOException e) {

        }
    }
}

From source file:Main.java

/**
 * Closes the given socket./*from w  ww .  j av  a 2 s  .  co m*/
 * 
 * @param socket
 *            The socket to close
 */
public static void close(Socket socket) {
    if (socket != null) {
        try {
            socket.close();
        } catch (IOException ioe1) {
            /* ignore. */
        }
    }
}

From source file:com.muleinaction.GreenMailUtilities.java

public static void waitForStartup(String host, int port, int count, long wait) throws InterruptedException {
    for (int i = 0; i < count; ++i) {
        Thread.sleep(wait);//from   w  w  w . j  a  va  2 s.  c  o m
        try {
            Socket socket = new Socket(host, port);
            socket.close();
            logger.info("Successful connection made to port " + port);
            return;
        } catch (Exception e) {
            logger.warn("Could not connect to server on " + host + ":" + port + " - " + e.getMessage());
        }
    }
    throw new RuntimeException("Server failed to start within " + (count * wait) + "ms");
}

From source file:Main.java

public static boolean isPortOpen(final String ip, final int port, final int timeout) {
    try {/* w  w w.  j a  v  a2s .  c  o m*/
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress(ip, port), timeout);
        socket.close();
        return true;
    }

    catch (ConnectException ce) {
        ce.printStackTrace();
        return false;
    }

    catch (Exception ex) {
        ex.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static boolean isPortOpen(final String ip, final int port, final int timeout) {
    try {/*www. j  a va2  s  .co  m*/
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress(ip, port), timeout);
        socket.close();
        return true;
    }

    catch (ConnectException ce) {
        //ce.printStackTrace();
        return false;
    }

    catch (Exception ex) {
        //ex.printStackTrace();
        return false;
    }
}

From source file:Main.java

/**
 * Closes {@code socket}, ignoring any checked exceptions. Does nothing if
 * {@code socket} is null.//from  w w w . j a  va2  s .co  m
 */
public static void closeQuietly(Socket socket) {
    if (socket != null) {
        try {
            socket.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}

From source file:Main.java

public static void closeQuietly(Socket socket) {
    if (socket != null) {
        try {/*  w  w w.jav a  2  s  .  c  o  m*/
            socket.close();
        } catch (AssertionError e) {
            if (!isAndroidGetsocknameError(e))
                throw e;
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}

From source file:Main.java

/**
 * Closes a socket while suppressing any {@code IOException} that occurs.
 * @param socket the socket to close/*from   www  .  j av  a2 s. c  o m*/
 */
public static void closeQuietly(Socket socket) {
    if (socket == null)
        return;
    try {
        socket.close();
    } catch (IOException ex) {
        assert true; // avoid an empty catch
    }
}