[Zerofile-svn] SF.net SVN: zerofile: [32] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-06 19:36:05
|
Revision: 32
http://zerofile.svn.sourceforge.net/zerofile/?rev=32&view=rev
Author: karl-bengtsson
Date: 2007-11-06 11:35:39 -0800 (Tue, 06 Nov 2007)
Log Message:
-----------
*) Added a static resolver class with a single method used to find out information about a given XMPP service on the network.
*) Further refined the ZeroconfBrowsing class
*) Modified the attributes of the XMPPLinkLocalHost class - this class should only hold information that is readily available when browsing for services, not detailed information for which a resolving operation is required. Such detailed information (IP address, port number, nick name, etc) should be fetched only when needed, to minimize network traffic.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfBrowsing.java
Added Paths:
-----------
trunk/src/ZeroconfResolving.java
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-06 18:22:06 UTC (rev 31)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-06 19:35:39 UTC (rev 32)
@@ -1,12 +1,43 @@
// Stub class, to represent a compatible XMPP-capable host on the ZeroConf network
public class XMPPLinkLocalHost {
- private String _ipAddress;
- public XMPPLinkLocalHost(String ipAddress)
+ private String _serviceName;
+ private String _nickName;
+ private String _firstName;
+ private String _lastName;
+
+ public XMPPLinkLocalHost(String serviceName)
{
- _ipAddress = ipAddress;
+ _serviceName = serviceName;
}
- public String getIPAddress()
+
+ /*public String getIPAddress()
{
return _ipAddress;
+ }*/
+
+ public String getServiceName()
+ {
+ return _serviceName;
}
+
+ public String getFirstName()
+ {
+ return _firstName;
+ }
+
+ public String getLastName()
+ {
+ return _lastName;
+ }
+
+ public String toString()
+ {
+ if (_nickName != null)
+ return _nickName;
+ else
+ if (_firstName != null && _lastName != null)
+ return _firstName + " " + _lastName;
+ else
+ return _serviceName;
+ }
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-06 18:22:06 UTC (rev 31)
+++ trunk/src/ZeroFile.java 2007-11-06 19:35:39 UTC (rev 32)
@@ -15,14 +15,18 @@
ZeroconfRegistration.registerService();
ZeroconfRegistration.set1st("Testar");
ZeroconfRegistration.setLast("Nisse");
+ ZeroconfBrowsing.startBrowsing();
+ /*
ZeroFileMainWindow.addContact("Test 1");
ZeroFileMainWindow.addContact("Test 2");
ZeroFileMainWindow.addContact("Test 3");
ZeroFileMainWindow.addContact("Test 4");
ZeroFileMainWindow.removeContact("Test 3");
+ */
Thread.sleep(5000);
ZeroconfRegistration.setStatus("away");
Thread.sleep(15000);
+ ZeroconfBrowsing.stopBrowsing();
ZeroconfRegistration.unregisterService();
}
catch(Exception e)
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-06 18:22:06 UTC (rev 31)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-06 19:35:39 UTC (rev 32)
@@ -17,11 +17,11 @@
private static JComboBox _statusLista;
private static DefaultListModel _contactListModel;
private static JList _contactList;
- static void addContact(String c)
+ static void addContact(Object c)
{
_contactListModel.addElement(c);
}
- static void removeContact(String c)
+ static void removeContact(Object c)
{
_contactListModel.removeElement(c);
}
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-06 18:22:06 UTC (rev 31)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-06 19:35:39 UTC (rev 32)
@@ -1,8 +1,39 @@
-// TODO
+import com.apple.dnssd.*;
+
public class ZeroconfBrowsing {
- static XMPPLinkLocalHost[] findXMPPHosts()
+ private static DNSSDService _s;
+ static void startBrowsing()
+ throws DNSSDException, InterruptedException
{
- XMPPLinkLocalHost[] testArr = {new XMPPLinkLocalHost("192.168.0.1"),new XMPPLinkLocalHost("192.168.0.2")};
- return testArr;
+ _s = DNSSD.browse("_presence._tcp",new BrowseListener() {
+ public void operationFailed(DNSSDService service, int errorCode)
+ {
+ System.out.println("Browse failed: " + errorCode);
+ System.exit(-1);
+ }
+ public void serviceFound(DNSSDService browser, int flags, int ifIndex,
+ String name, String regType, String domain)
+ {
+ System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
+ try
+ {
+ ZeroconfResolving.getHost(name);
+ }
+ catch (Exception e)
+ {
+ System.out.println("Error: " + e.getStackTrace());
+ }
+ }
+ public void serviceLost(DNSSDService browser, int flags, int ifIndex,
+ String name, String regType, String domain)
+ {
+ System.out.println("Lost: " + name);
+ }
+ });
+ System.out.println("Starting browsing...");
}
+ static void stopBrowsing(){
+ _s.stop();
+ System.out.println("Stopped browsing");
+ }
}
Added: trunk/src/ZeroconfResolving.java
===================================================================
--- trunk/src/ZeroconfResolving.java (rev 0)
+++ trunk/src/ZeroconfResolving.java 2007-11-06 19:35:39 UTC (rev 32)
@@ -0,0 +1,35 @@
+import com.apple.dnssd.*;
+
+/*
+ * A static class with methods for resolving hosts once we've found them
+ */
+
+public class ZeroconfResolving {
+ private static DNSSDService _r;
+ static void getHost(String serviceName)
+ throws DNSSDException, InterruptedException
+ {
+ _r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, serviceName, "_presence._tcp", "local", new ResolveListener()
+ {
+ public void operationFailed(DNSSDService service,int errorCode)
+ {
+ System.out.println("Resolved failed " + errorCode);
+ System.exit(-1);
+ }
+ public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
+ String fullName, String hostName, int port, TXTRecord txtRecord)
+ {
+ System.out.println("Host resolved: " + hostName + ":" + port);
+ System.out.println("Flags: " + flags + ", ifIndex: " + ifIndex + ", FQDN: " + fullName);
+ for (int i = 0; i < txtRecord.size(); i++)
+ {
+ String key = txtRecord.getKey(i);
+ String value = txtRecord.getValueAsString(i);
+ if (key.length() > 0)
+ System.out.println("\t" + key + "=" + value);
+ }
+ _r.stop();
+ }
+ });
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|