1 11 12 package org.jivesoftware.messenger.net; 13 14 import org.jivesoftware.messenger.container.BasicModule; 15 import org.jivesoftware.messenger.XMPPServer; 16 import org.jivesoftware.messenger.XMPPServerInfo; 17 import org.jivesoftware.messenger.ServerPort; 18 import org.jivesoftware.util.Log; 19 import org.jivesoftware.admin.AdminConsole; 20 21 import javax.jmdns.JmDNS; 22 import javax.jmdns.ServiceInfo; 23 import java.io.IOException ; 24 import java.util.Iterator ; 25 26 35 public class MulticastDNSService extends BasicModule { 36 37 private JmDNS jmdns; 38 private ServiceInfo serviceInfo; 39 40 public MulticastDNSService() { 41 super("Multicast DNS Service"); 42 } 43 44 public void initialize(XMPPServer server) { 45 46 } 47 48 public void start() throws IllegalStateException { 49 if (jmdns != null) { 50 Runnable startService = new Runnable () { 51 public void run() { 52 XMPPServerInfo info = XMPPServer.getInstance().getServerInfo(); 53 Iterator ports = info.getServerPorts(); 54 int portNum = -1; 55 while (ports.hasNext()) { 56 ServerPort port = (ServerPort)ports.next(); 57 if (port.isClientPort() && !port.isSecure()) { 58 portNum = port.getPort(); 59 } 60 } 61 try { 62 if (jmdns == null) { 63 jmdns = new JmDNS(); 64 } 65 if (portNum != -1) { 66 String serverName = AdminConsole.getAppName(); 67 serviceInfo = new ServiceInfo("_xmpp-client._tcp.local.", 68 serverName, portNum, 0, 0, "XMPP Server"); 69 jmdns.registerService(serviceInfo); 70 } 71 } 72 catch (IOException ioe) { 73 Log.error(ioe); 74 } 75 } 76 }; 77 new Thread (startService).start(); 78 } 79 } 80 81 82 public void stop() { 83 if (jmdns != null) { 84 try { 85 jmdns.close(); 86 } 87 catch (Exception e) { } 88 } 89 } 90 91 public void destroy() { 92 if (jmdns != null) { 93 jmdns = null; 94 } 95 } 96 } | Popular Tags |