Esempio n. 1
0
 // Analysis disable once FunctionNeverReturns
 public static void Daemon(ushort port, Array uri, Guid serverID)
 {
     Raw raw = new Raw (port);
     SimpleDiscovery sd = new SimpleDiscovery (raw);
     HTTPRequest httpRequest = new HTTPRequest ();
     Dictionary<string, object> args = new Dictionary<string, object> ();
     args.Add ("URI", uri);
     args.Add ("SERVERID", serverID.ToString ());
     httpRequest.Arguments = args;
     sd.SetMessageInformation (httpRequest.Arguments);
     sd.DiscoverMessageReceived += (sender, e) => {
         try {
             if ((string)(e.Request.Arguments ["SERVERID"]) != serverID.ToString ())
                 Console.Error.WriteLine ("Another daemon is running on the network.");
         } catch {
             Console.Error.WriteLine ("Another program is using our port.");
         }
     };
     try {
         while (true)
             System.Threading.Thread.Sleep (1000);
     } finally {
         raw.Stop ();
     }
 }
 public CachedDiscoveryManager(short port)
 {
     Guid id = Guid.NewGuid ();
     Raw r = new Raw (port);
     SimpleDiscovery sd = new SimpleDiscovery (r);
     Dictionary<string, object> arguments = new Dictionary<string, object> ();
     arguments.Add ("ID", id.ToString ());
     arguments.Add ("HOST", System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties ().DomainName);
     arguments.Add ("PORT", port.ToString ());
     sd.DiscoverMessageReceived += (sender, e) => {
         Guid msgID = Guid.Parse (e.Request.Arguments ["ID"].ToString ());
         if (hosts.ContainsKey (msgID)) {
             lock (hosts)
                 hosts.Add (msgID, e.Request);
         } else {
             lock (hosts)
                 hosts [msgID].Arguments = e.Request.Arguments;
         }
     };
     sd.SetMessageInformation (arguments);
 }