[Zerofile-svn] SF.net SVN: zerofile: [25] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-06 14:03:32
|
Revision: 25
http://zerofile.svn.sourceforge.net/zerofile/?rev=25&view=rev
Author: karl-bengtsson
Date: 2007-11-06 06:03:07 -0800 (Tue, 06 Nov 2007)
Log Message:
-----------
Started moving the registration logic into it's own class using static class methods.
Modified Paths:
--------------
trunk/src/ZeroFile.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-06 12:02:00 UTC (rev 24)
+++ trunk/src/ZeroFile.java 2007-11-06 14:03:07 UTC (rev 25)
@@ -20,10 +20,15 @@
try
{
//If name specified, use it, else use default name
- String name = (args.length > 0) ? args[0] : null;
+ //String name = (args.length > 0) ? args[0] : null;
// Let system allocate us an available port to listen on
ServerSocket s = new ServerSocket(0);
- new ZeroConfRegistrationTest(name, s.getLocalPort( ));
+ ZeroconfRegistration.registerService(s.getLocalPort());
+ Thread.sleep(5000);
+ ZeroconfRegistration.setStatus("dnd");
+ Thread.sleep(15000);
+ ZeroconfRegistration.unregisterService();
+ //new ZeroConfRegistrationTest(name, s.getLocalPort( ));
}
catch(Exception e)
{
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-06 12:02:00 UTC (rev 24)
+++ trunk/src/ZeroconfRegistration.java 2007-11-06 14:03:07 UTC (rev 25)
@@ -1,3 +1,5 @@
+import com.apple.dnssd.DNSSD;
+import com.apple.dnssd.DNSSDException;
import com.apple.dnssd.DNSSDRegistration;
import com.apple.dnssd.DNSSDService;
import com.apple.dnssd.RegisterListener;
@@ -3,41 +5,57 @@
import com.apple.dnssd.TXTRecord;
-public class ZeroconfRegistration implements RegisterListener{
- private TXTRecord _TXTRecord = new TXTRecord();
-
- public void serviceRegistered(DNSSDRegistration registration, int flags,
- String serviceName, String regType, String domain)
+public class ZeroconfRegistration
+{
+ private static TXTRecord _txtRecord = new TXTRecord();
+ private static DNSSDRegistration _r;
+
+ static void registerService(int port)
+ throws DNSSDException, InterruptedException
{
- // TODO
- System.out.println("Registered Name : " + serviceName);
- System.out.println(" Type : " + regType);
- System.out.println(" Domain: " + domain);
+ _r = DNSSD.register("servicename", "_presence._tcp", port, new RegisterListener()
+ {
+ public void serviceRegistered(DNSSDRegistration registration, int flags,
+ String serviceName, String regType, String domain)
+ {
+ // TODO
+ System.out.println("Registered Name : " + serviceName);
+ System.out.println(" Type : " + regType);
+ System.out.println(" Domain: " + domain);
+ }
+ public void operationFailed(DNSSDService service, int errorCode)
+ {
+ // TODO
+ System.out.println("Registration failed: " + errorCode);
+ }
+ });
+ _txtRecord.set("txtvers", "1");
+ _txtRecord.set("status","avail");
+ _txtRecord.set("email","tes...@te...");
+ _txtRecord.set("jid","te...@te...");
+ _txtRecord.set("vc","SDUR!XN");
+ _txtRecord.set("port.p2pj",""+port);
+ _txtRecord.set("1st","Nisse");
+ _txtRecord.set("last","Nilsson");
+ _r.getTXTRecord().update(0, _txtRecord.getRawBytes(), 0);
}
- public void operationFailed(DNSSDService service, int errorCode)
+ static void unregisterService()
{
- // TODO
- System.out.println("Registration failed: " + errorCode);
+ _r.stop();
}
- public void registerService()
+ static String getStatus()
{
- // TODO
+ return _txtRecord.getValueAsString("status");
}
- public void unregisterService()
+ static void setStatus(String s)
+ throws DNSSDException, InterruptedException
{
- // TODO
+ if (_r != null)
+ {
+ _txtRecord.set("status", s);
+ _r.getTXTRecord().update(0, _txtRecord.getRawBytes(), 0);
+ }
}
-
- public String getStatus()
- {
- return _TXTRecord.getValueAsString("status");
-
- }
-
- public void setStatus(String s)
- {
- _TXTRecord.set("status", s);
- }
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|