List of usage examples for java.net Socket close
public synchronized void close() throws IOException
From source file:com.ery.ertc.estorm.util.ToolUtil.java
public static void close(Socket c) { if (c != null) { try {// w w w . ja va2 s . com c.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.buaa.cfs.utils.IOUtils.java
/** * Closes the socket ignoring {@link IOException} * * @param sock the Socket to close//from w ww . j a va2 s .com */ public static void closeSocket(Socket sock) { if (sock != null) { try { sock.close(); } catch (IOException ignored) { } } }
From source file:com.ery.ertc.estorm.util.IOUtils.java
/** * Closes the socket ignoring {@link IOException} * // w ww . ja v a2 s. c o m * @param sock * the Socket to close */ public static void closeSocket(Socket sock) { // avoids try { close() } dance if (sock != null) { try { sock.close(); } catch (IOException ignored) { } } }
From source file:com.codefollower.lealone.omid.TestUtils.java
public static void waitForSocketListening(String host, int port, int sleepTimeMillis) throws UnknownHostException, IOException, InterruptedException { while (true) { Socket sock = null; try {//from ww w. ja v a 2 s .c o m sock = new Socket(host, port); } catch (IOException e) { // ignore as this is expected Thread.sleep(sleepTimeMillis); continue; } finally { if (sock != null) { sock.close(); } } LOG.info("Host " + host + ":" + port + " is up"); break; } }
From source file:com.aqnote.shared.cryptology.util.lang.StreamUtil.java
public static void close(Socket socket) { try {// w w w . j a va 2 s. co m if (socket != null && !socket.isClosed()) socket.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mirth.connect.connectors.tcp.SocketUtil.java
public static void closeSocket(Socket socket) throws IOException { if (socket != null) { /*//w w w .j a va 2 s . c o m * MIRTH-2984: The shutdownInput() and shutdownOutput() methods are no longer being * called. On Windows this causes a RST packet to be sent to the remote side if there * are still bytes available in the socket's input stream. */ socket.close(); } }
From source file:fitnesse.http.ResponseParser.java
public static ResponseParser performHttpRequest(String hostname, int hostPort, RequestBuilder builder) throws IOException { Socket socket = new Socket(hostname, hostPort); OutputStream socketOut = socket.getOutputStream(); InputStream socketIn = socket.getInputStream(); builder.send(socketOut);/*from w w w. j av a 2 s .co m*/ socketOut.flush(); try { return new ResponseParser(socketIn); } finally { socketOut.close(); socket.close(); } }
From source file:org.openbaton.integration.test.utils.Utils.java
public static boolean available(String host, String port) { try {/*from w ww .jav a 2s .c o m*/ Socket s = new Socket(host, Integer.parseInt(port)); log.info("Server is listening on port " + port + " of " + host); s.close(); return true; } catch (IOException ex) { // The remote host is not listening on this port log.warn("Server is not listening on port " + port + " of " + host); return false; } }
From source file:esg.common.Utils.java
public static boolean poke(String host, int port, int timeout) { boolean ret = false; Socket socket = null; try {/*w w w . j a v a 2 s .c om*/ (socket = new Socket()).connect(new InetSocketAddress(java.net.InetAddress.getByName(host), port), timeout); socket.close(); ret = true; } catch (Throwable t) { log.error(t.getMessage()); } finally { try { socket.close(); } catch (Throwable t) { } } return ret; }
From source file:com.googlecode.icegem.cacheutils.common.Utils.java
/** * Checks if the socket of specified host and port is alive. * //from w w w . j a v a 2 s .c om * @param host * - the host. * @param port * - the port. * @return - true if alive, false otherwise. */ public static boolean isSocketAlive(String host, int port) { boolean socketAlive = false; Socket socket = null; try { socket = new Socket(host, port); socketAlive = socket.isConnected(); } catch (Throwable t) { // do nothing } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { // do nothing } } } return socketAlive; }