Code example for Socket

Methods: bind, close, connect

0
    } 
 
    public boolean checkCondition(long elapsedTimeInMs) {
        Socket socket = null;
        try { 
            socket = new Socket();
            socket.bind(null);
            socket.connect(new InetSocketAddress(host, port), timeout);
            socket.close();
            return true; 
        } catch (IOException e) {
            return false; 
        } finally { 
            if (socket != null) {
                try { 
                    socket.close();
                } catch (IOException e) {
                    // ignore 
                } 
            } 
        }