FileDocCategorySizeDatePackage
TestResolveWithMonitoring.javaAPI DocExample2485Sun Jul 10 18:48:34 BST 2005None

TestResolveWithMonitoring

public class TestResolveWithMonitoring extends Object implements ResolveListener, QueryListener

Fields Summary
private DNSSDService
monitorQ
Constructors Summary
public TestResolveWithMonitoring(String name, String domain)

		System.out.println("TestResolveWithMonitoring Starting");
		DNSSDService r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES,
			name, "_example._tcp", domain, this);
		System.out.println("TestResolveWithMonitoring Running");
		Thread.sleep(30000);
		System.out.println("TestResolveWithMonitoring Stopping");
		if (monitorQ == null) r.stop();
		else monitorQ.stop();
		Thread.sleep(1);
		
Methods Summary
public static voidmain(java.lang.String[] args)

		if (args.length != 2)
			{
			System.out.println("Usage: java TestResolveWithMonitoring name dom");
			System.exit(-1);
			}
		else
			{
			try
				{
				new TestResolveWithMonitoring(args[0], args[1]);
				}
			catch (Exception e)
				{
				e.printStackTrace();
				System.exit(-1);
				} 
			}
		
public voidoperationFailed(DNSSDService service, int errorCode)

	
	// Display error message on failure
	     
		
		System.out.println("Resolve failed " + errorCode);
		System.exit(-1);
		
public voidqueryAnswered(DNSSDService query, int flags, int ifIndex, java.lang.String fullName, int rrtype, int rrclass, byte[] rdata, int ttl)

		if ((flags & 2) != 0)
			{
			boolean blankPrinted = false;
			TXTRecord txtRecord = new TXTRecord(rdata);
			for (int i = 0; i < txtRecord.size(); i++)
				{
				String key = txtRecord.getKey(i);
				String value = txtRecord.getValueAsString(i);
				if (key.length() > 0)
					{
					if (!blankPrinted)
						{
						blankPrinted = true;
						System.out.println();
						}
					System.out.println("\t" + key + "=" + value);
					}
				}
			}
		
public voidserviceResolved(DNSSDService resolver, int flags, int ifIndex, java.lang.String fullName, java.lang.String hostName, int port, TXTRecord txtRecord)

		System.out.println("Service Resolved: " + hostName + ":" + port);
		System.out.println("Flags: " + flags +
			", ifIndex: " + ifIndex + ", FQDN: " + fullName);

		// Now that we've got a resolve result,
		// start monitoring the TXT record and stop the resolve call.
		try { monitorQ = DNSSD.queryRecord(0, ifIndex, fullName, 16, 1, this); }
		catch (Exception e) { e.printStackTrace(); System.exit(-1); }
		resolver.stop();
		try { Thread.sleep(1); }
		catch (Exception e) { e.printStackTrace(); System.exit(-1); }