FileDocCategorySizeDatePackage
TestRegister.javaAPI DocExample1823Thu Jul 07 07:41:52 BST 2005None

TestRegister

public class TestRegister extends Object implements RegisterListener

Fields Summary
Constructors Summary
public TestRegister(String name, int port)

		System.out.println("Registration Starting");
		System.out.println("Requested Name: " + name);
		System.out.println("          Port: " + port);
		//DNSSDRegistration r = DNSSD.register("Moët & Chandon", "_example._tcp", 9099, this);
		DNSSDRegistration r = DNSSD.register(name, "_example._tcp", port, this);
		Thread.sleep(3000);
		DNSRecord rec = r.getTXTRecord();
		byte[] x = new byte[1];
		DNSRecord rec2 = r.addRecord(0, 0, x, 0);
		Thread.sleep(30000); // Wait thirty seconds, then exit
		System.out.println("Registration Stopping");
		r.stop();
		
Methods Summary
public static voidmain(java.lang.String[] args)

		if (args.length > 1)
			{
			System.out.println("Usage: java TestRegister name");
			System.exit(-1);
			}
		else
			{
			try
				{
				// If name specified, use it, else use default name
				String name = (args.length > 0) ? args[0] : null;
				// Let system allocate us an available port to listen on
				ServerSocket s = new ServerSocket(0);
				new TestRegister(name, s.getLocalPort());
				}
			catch (Exception e)
				{
				e.printStackTrace();
				System.exit(-1);
				} 
			}
		
public voidoperationFailed(DNSSDService service, int errorCode)

		System.out.println("Registration failed " + errorCode);
		
public voidserviceRegistered(DNSSDRegistration registration, int flags, java.lang.String serviceName, java.lang.String regType, java.lang.String domain)

		System.out.println("Registered Name  : " + serviceName);
		System.out.println("           Type  : " + regType);
		System.out.println("           Domain: " + domain);