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

/**
 * Simple utility to close {@link Socket} instance.
 * See {@link MozcUtil#close(Closeable,boolean)} for details.
 *///w  w w .ja  v a2  s.  co  m
public static void close(Socket socket, boolean ignoreIOException) throws IOException {
    try {
        socket.close();
    } catch (IOException e) {
        if (!ignoreIOException) {
            throw e;
        }
    }
}

From source file:Main.java

public static void closeQuietly(Socket s) {
    if (s != null) {
        try {/*from   www  .j a  v a2s.  c o m*/
            s.close();
        } catch (IOException e) {
        }
    }
}

From source file:Main.java

public static void closeQuietly(Socket sock) {
    if (sock != null) {
        try {//from   ww  w.  java2s .c o  m
            sock.close();
        } catch (IOException var2) {
            ;
        }
    }

}

From source file:org.cloudfoundry.identity.uaa.api.client.test.AbstractOperationTest.java

protected static void init() throws Exception {
    try {/*from   w  ww.  ja va 2 s . c  o m*/
        Socket test = new Socket("localhost", 8080);
        uaaRunning = true;
        test.close();
    } catch (IOException e) {
        System.err.println("UAA is not running, skip these tests");
        uaaRunning = false;
        return;
    } finally {
        String baseUrl = "http://localhost:8080/uaa";

        ClientCredentialsResourceDetails credentials = new ClientCredentialsResourceDetails();
        credentials.setAccessTokenUri(baseUrl + "/oauth/token");
        //         credentials.setAuthenticationScheme(AuthenticationScheme.header);
        credentials.setClientAuthenticationScheme(AuthenticationScheme.header);
        credentials.setClientId("admin");
        credentials.setClientSecret("adminsecret");

        connection = UaaConnectionFactory.getConnection(new URL(baseUrl), credentials);
    }
}

From source file:Main.java

public final static void closeQuietly(Socket s) {
    try {/*from   www.  ja v  a  2s .  c o  m*/
        if (s != null)
            s.close();
    } catch (Exception e) {
        Log.e("OpenVPN", "closing Socket", e);
    }
}

From source file:Main.java

/**
 * Safely close a socket, absorbing exceptions and handling
 * <code>null</code> graciously.
 * /*from w  w  w  .  j  a  v a2 s . c  o m*/
 * @param socket object to close.
 */
public static void safeClose(Socket socket) {
    try {
        if (socket != null) {
            socket.close();
        }
    } catch (IOException e) {
        log(socket, e);
    }
}

From source file:com.stacksync.desktop.Stacksync.java

private static boolean isAlreadyRunning() {
    try {/*from  w  w  w  .j  a v  a2  s. c om*/
        Socket clientSocket = new Socket("localhost", Constants.COMMANDSERVER_PORT);
        clientSocket.close();
        return true;
    } catch (UnknownHostException ex) {
        System.out.println("Error not found localhost. Exception: " + ex.getMessage());
        return false;
    } catch (IOException ex) {
        //System.out.println("Error with socket. Exception: " + ex.getMessage());
        return false;
    }
}

From source file:com.liferay.sync.engine.util.SyncSystemTestUtil.java

protected static boolean isPortInUse(int port) {
    try {//from w w  w  .  j a  v a2s.c  o  m
        Socket socket = new Socket("localhost", port);

        socket.close();

        return true;
    } catch (IOException ioe) {
        return false;
    }
}

From source file:Main.java

public static String getSocketLocalIpAddress() {
    String ipAddress = "";
    Socket socket;
    try {// www.  j a  v  a  2  s.  c o m
        socket = new Socket("www.google.com", 80);
        ipAddress = socket.getLocalAddress().toString();
        ipAddress = ipAddress.replace("/", "");
        Log.i(TAG, "IP by socket: " + ipAddress);
        socket.close();
        return ipAddress;
    } catch (Exception e) {
        Log.i(TAG, e.getMessage());
    }
    return ipAddress;
}

From source file:net.ruthandtodd.gpssync.rkoauth.RunkeeperOAuthClient.java

private static int getEphemeralPort() throws IOException {
    Socket s = new Socket();
    s.bind(null);//from ww w.  ja va2 s  .c o m
    try {
        return s.getLocalPort();
    } finally {
        s.close();
    }
}