List of usage examples for java.net Socket isBound
public boolean isBound()
From source file:Main.java
public static void main(String[] args) throws Exception { Socket client = new Socket("google.com", 80); System.out.println(client.isBound()); client.close();//from w w w. ja va2 s. c om }
From source file:mc.lib.network.NetworkHelper.java
private static boolean testConnection(String url) { Socket s = null; boolean res = false; try {//from w ww . j av a2 s .com s = new Socket(url, 80); if (s.isBound() && s.isConnected()) { res = true; } } catch (IOException e) { Log.e(LOGTAG, "Error on testConnection to " + url, e); } finally { if (s != null) StreamHelper.close(s); } return res; }
From source file:com.linkedin.databus2.test.TestUtil.java
/** * Checks if a server is running on a given host and port * @param host the server host/*from www. j a va 2s. com*/ * @param port the server port * @param log logger for diagnostic messages (can be null) * @return true if successful * @throws IOException */ public static boolean checkServerRunning(String host, int port, Logger log, boolean logError) { boolean success = false; try { Socket socket = new Socket(host, port); log.info("host=" + host + " port=" + port); log.info("Socket Info:" + socket.toString()); log.info("IsConnected=" + socket.isConnected() + " isClosed=" + socket.isClosed() + " isBound=" + socket.isBound()); success = socket.isConnected(); socket.close(); } catch (ConnectException ce) { if (null != log) log.error("Fail to connect to port:" + port); if (logError && null != log) log.error("Connect error", ce); success = false; } catch (IOException e) { if (logError && null != log) log.error("connect error", e); } catch (RuntimeException e) { if (logError && null != log) log.error("runtime error", e); } return success; }
From source file:org.mule.providers.ldap.util.DSManager.java
public static boolean checkSocketNotConnected() { try {/* ww w.j ava 2s . co m*/ Socket s = new Socket("localhost", 10389); if (s.isConnected()) { logger.debug("client socket is connected (server socket bound)"); } s.close(); return false; } catch (Exception e) { logger.debug("client Socket not connected " + e.toString()); } try { ServerSocket s = new ServerSocket(10389); if (s.isBound()) { logger.debug("server socket is bound (=was therefore free)"); } s.close(); return true; } catch (Exception e) { logger.debug("Server socket already bound " + e.toString()); // e.printStackTrace(); return false; } }
From source file:org.mule.transport.ldap.util.DSManager.java
public static boolean checkSocketNotConnected() { try {/* ww w . ja v a2 s . co m*/ final Socket s = new Socket("localhost", 10389); if (s.isConnected()) { logger.debug("client socket is connected (server socket bound)"); } s.close(); return false; } catch (final Exception e) { logger.debug("client Socket not connected " + e.toString()); } try { final ServerSocket s = new ServerSocket(10389); if (s.isBound()) { logger.debug("server socket is bound (=was therefore free)"); } s.close(); return true; } catch (final Exception e) { logger.debug("Server socket already bound " + e.toString()); // e.printStackTrace(); return false; } }
From source file:org.jmxtrans.embedded.util.pool.SocketOutputStreamPoolFactory.java
/** * Defensive approach: we test all the "<code>Socket.isXXX()</code>" flags. *//* ww w . j a v a 2 s . co m*/ @Override public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketOutputStream> socketOutputStreamRef) { Socket socket = socketOutputStreamRef.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:org.apache.jmeter.visualizers.backend.graphite.SocketOutputStreamPoolFactory.java
/** *//*from w w w . java 2 s . co m*/ @Override public boolean validateObject(SocketConnectionInfos hostAndPort, PooledObject<SocketOutputStream> socketOutputStream) { Socket socket = socketOutputStream.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:org.jmxtrans.embedded.util.pool.SocketWriterPoolFactory.java
/** * Defensive approach: we test all the "<code>Socket.isXXX()</code>" flags. *//*from w w w . j a va 2 s . co m*/ @Override public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketWriter> socketWriterRef) { Socket socket = socketWriterRef.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:voldemort.store.socket.SocketPoolableObjectFactory.java
public boolean validateObject(Object key, Object value) { SocketAndStreams sands = (SocketAndStreams) value; Socket s = sands.getSocket(); boolean isValid = !s.isClosed() && s.isBound() && s.isConnected(); if (!isValid && logger.isDebugEnabled()) logger.debug("Socket connection " + sands + " is no longer valid, closing."); return isValid; }
From source file:com.googlecode.jmxtrans.connections.SocketFactory.java
/** * Validates that the socket is good./* w w w.j ava 2 s . co m*/ */ @Override public boolean validateObject(InetSocketAddress address, Socket socket) { if (socket == null) { log.error("Socket is null [{}]", address); return false; } if (!socket.isBound()) { log.error("Socket is not bound [{}]", address); return false; } if (socket.isClosed()) { log.error("Socket is closed [{}]", address); return false; } if (!socket.isConnected()) { log.error("Socket is not connected [{}]", address); return false; } if (socket.isInputShutdown()) { log.error("Socket input is shutdown [{}]", address); return false; } if (socket.isOutputShutdown()) { log.error("Socket output is shutdown [{}]", address); return false; } return true; }