FileDocCategorySizeDatePackage
HostAlive.javaAPI DocExample2113Thu Feb 28 05:24:02 GMT 2002None

HostAlive.java

import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.Extension.*;
import java.net.InetAddress;

public class HostAlive
{
  public static final String SERVER   = "gnu.pipetree.com";
  public static final String USER     = "myserver";
  public static final String PASSWORD = "secret";
  public static final String RESOURCE = "alive";

  public static void main(String argv[])
  {

    ConnectionBean cb=new ConnectionBean();

    InetAddress addr;

    try
    {
      cb.connect(addr=InetAddress.getByName(SERVER));
    }
    catch (java.net.UnknownHostException e)
    { 
      //from getByName()
      System.out.println("Cannot resolve " + SERVER + ":" + e.toString());
      return;
    }
    catch (java.io.IOException e)
    {
      //from connect()
       System.out.println("Cannot connect to " + SERVER);
       return;
    }

    InfoQueryBuilder iqb=new InfoQueryBuilder();
    InfoQuery iq;
    IQAuthBuilder iqAuthb=new IQAuthBuilder();

    iqb.setType("set");


    iqAuthb.setUsername(USER);
    iqAuthb.setPassword(PASSWORD);
    iqAuthb.setResource(RESOURCE);

    try
    {
      iqb.addExtension(iqAuthb.build());
    }
    catch (InstantiationException e)
    {
      //building failed ?
      System.out.println("Fatal Error on Auth object build:");
      System.out.println(e.toString());
      System.exit(0);
    }


    try
    {
      //build the full InfoQuery packet
      iq=(InfoQuery)iqb.build();
    }
    catch (InstantiationException e)
    {
      //building failed ?
      System.out.println("Fatal Error on IQ object build:");
      System.out.println(e.toString());
      return;
    }

    cb.send(iq);

    PresenceBuilder pb=new PresenceBuilder();
    pb.setStatus(argv[0]);

    try
    {
      cb.send(pb.build());
    }
    catch (InstantiationException e)
    {
      System.out.println("Fatal Error on Presence object build:");
      System.out.println(e.toString());
      return;
    }

    while (true) {
      try {
        Thread.sleep(9999);
      }
      catch (InterruptedException e)
      {
        System.out.println("timeout!");
      }
    }