FileDocCategorySizeDatePackage
Socket.javaAPI DocApache Ant 1.702634Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs.condition

Socket

public class Socket extends org.apache.tools.ant.ProjectComponent implements Condition
Condition to wait for a TCP/IP socket to have a listener. Its attributes are: server - the name of the server. port - the port number of the socket.
since
Ant 1.5

Fields Summary
private String
server
private int
port
Constructors Summary
Methods Summary
public booleaneval()

return
true if a socket can be created
exception
BuildException if the attributes are not set

        if (server == null) {
            throw new BuildException("No server specified in socket "
                                     + "condition");
        }
        if (port == 0) {
            throw new BuildException("No port specified in socket condition");
        }
        log("Checking for listener at " + server + ":" + port,
            Project.MSG_VERBOSE);
        java.net.Socket s = null;
        try {
            s = new java.net.Socket(server, port);
        } catch (IOException e) {
            return false;
        } finally {
          if (s != null) {
            try {
              s.close();
            } catch (IOException ioe) {
              // Intentionally left blank
            }
          }
        }
        return true;
    
public voidsetPort(int port)
Set the port attribute

param
port the port number of the socket

        this.port = port;
    
public voidsetServer(java.lang.String server)
Set the server attribute

param
server the server name


                  
        
        this.server = server;