/** * This method creates the {@link EntryGroup}, adds some TXT records, a name, a service type and * port number. It then proceeds to publish the service. If there is a name conflict, it asks * Avahi4J for an alternate name and tries again. * * @throws Avahi4JException if there is an error creating the {@link EntryGroup} */ public void addService() throws Avahi4JException { int result; // create group group = client.createEntryGroup(this); // create some fake TXT records records.add("record1=1"); records.add("record2=2"); // add service System.out.println("\n\nAdding new service to group"); result = group.addService( Avahi4JConstants.AnyInterface, Protocol.ANY, "TestService", "_test._tcp", null, null, 1515, records); if (result != Avahi4JConstants.AVAHI_OK) { System.out.println( "Error adding service to group: " + Avahi4JConstants.getErrorString(result)); // try with an alternate name String newName = EntryGroup.findAlternativeServiceName("TestService"); System.out.println("\n\nRe-trying with new service name: " + newName); result = group.addService( Avahi4JConstants.AnyInterface, Protocol.ANY, newName, "_test._tcp", null, null, 1515, records); if (result != Avahi4JConstants.AVAHI_OK) System.out.println( "Error adding service to group: " + Avahi4JConstants.getErrorString(result)); } // commit service System.out.println("Committing group"); result = group.commit(); if (result != Avahi4JConstants.AVAHI_OK) System.out.println("Error committing group: " + Avahi4JConstants.getErrorString(result)); System.out.println("done"); }