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 DiscoverMessageReceivedEventArgs(IPEndPoint source, HTTPRequest request)
 {
     if (source == null)
         throw new ArgumentNullException ("source");
     if (request == null)
         throw new ArgumentNullException ("request");
     this.source = source;
     this.request = request;
 }
 public SimpleDiscovery(Raw raw)
 {
     this.raw = raw;
     if (raw == null)
         throw new ArgumentNullException ("raw");
     raw.SetReceiveCallback (MessageReceived);
     req = new HTTPRequest ();
     req.Method = "NOTIFY";
     req.URI = "*";
     req.Version = "HTTP/1.1";
 }
 void MessageReceived(Tuple<IPEndPoint, byte[]> obj)
 {
     byte[] buffer = obj.Item2;
     HTTPRequest recreq = new HTTPRequest (new MemoryStream (buffer));
     if (DiscoverMessageReceived != null)
         DiscoverMessageReceived.Invoke (this, new DiscoverMessageReceivedEventArgs (obj.Item1, recreq));
 }