January 2002
Beginner
480 pages
13h 15m
English
As you might have guessed from looking at Example 8-4,
we’re going to write HostAlive in Java, shown in Example 8-6. We’ll use the
JabberBeans
library; see Section P.4 in the Preface for details of where
to get this library and what the requirements are.
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 ...Read now
Unlock full access