//----< Test Stub >--------------------------------------------------

#if (TEST_SENDER)
        static void Main(string[] args)
        {
            Util.verbose = false;

            Console.Write("\n  starting CommService Sender");
            Console.Write("\n =============================\n");
            Console.Title = "CommService Sender";
            Sender sndr = new Sender("http://localhost:8081/CommService");

            sndr.processCommandLine(args);
            int     numMsgs = 5;
            int     counter = 0;
            Message msg     = null; while (true)

            {
                msg         = new Message();
                msg.fromUrl = sndr.localUrl;
                msg.toUrl   = sndr.remoteUrl;
                msg.content = "Message #" + (++counter).ToString();
                Console.Write("\n  sending {0}", msg.content);
                sndr.sendMessage(msg);
                Thread.Sleep(30);
                if (counter >= numMsgs)
                {
                    break;
                }
            }
            msg         = new Message();
            msg.fromUrl = sndr.localUrl;
            msg.toUrl   = "http://localhost:9999/CommService";
            msg.content = "no listener for this message";
            Console.Write("\n  sending {0}", msg.content);
            sndr.sendMessage(msg);
            msg         = new Message();
            msg.fromUrl = sndr.localUrl;
            msg.toUrl   = sndr.remoteUrl;
            msg.content = "Message #" + (++counter).ToString();
            Console.Write("\n  sending {0}", msg.content);
            sndr.sendMessage(msg);
            msg         = new Message();
            msg.fromUrl = sndr.localUrl;
            msg.toUrl   = sndr.remoteUrl;
            msg.content = "closeSender"; // message for self and Receiver
            Console.Write("\n  sending {0}", msg.content);
            sndr.sendMessage(msg);
        }
        // main function to send messages
        static void Main(string[] args)
        {
            Thread.Sleep(2000);
            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");
            Console.Title = "Client #1";
            Client clnt = new Client();

            clnt.processCommandLine(args);
            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);

            if (rcvr.StartService())
            {
                Action newact = clnt.doAction(rcvr);
                rcvr.doService(newact);
            }
            Sender  sndr = new Sender(clnt.localUrl); // Sender needs localUrl for start message
            Message msg  = new Message();

            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;
            Console.Write("\n  sender's url is {0}", msg.fromUrl);
            Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);
            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();                return;
            }
            XDocument doc = XDocument.Load("./../../../dbload.xml");

            Console.WriteLine(doc.ToString());
            Console.WriteLine(" xml  is loaded ");
            Console.WriteLine();
            XElement dbe   = doc.Element("root");
            int      count = Int32.Parse(dbe.Element("count").Value);

            for (int i = 0; i < count; i++)
            {
                foreach (var a in dbe.Elements("ClientMessage"))
                {
                    msg         = new Message();
                    msg.fromUrl = clnt.localUrl;
                    msg.toUrl   = clnt.remoteUrl;
                    Console.Write("\n  sending {0}\n", msg.content);
                    Console.Write("\n");
                    msg.content = a.ToString();
                    sndr.sendMessage(msg);
                    Thread.Sleep(200);
                }
            }
            Thread.Sleep(200);   // Wait for user to press a key to quit.
            // Ensures that client has gotten all server replies.
            Util.waitForUser();  // shut down this client's Receiver and Sender by sending close messages
            rcvr.shutDown();            sndr.shutdown();            Console.Write("\n\n");
        }
Esempio n. 3
0
        //function used to display the performance in WPF
        public void send_wpf_msg(ulong prc_time, Sender sndr)
        {
            Message wpf_msg = new Message();

            wpf_msg.toUrl   = "http://localhost:8081/CommService";
            wpf_msg.fromUrl = "http://localhost:8080/CommService";

            string lat_msg = "Server(8080) : Processing time = " + prc_time;

            wpf_msg.content = lat_msg;
            sndr.sendMessage(wpf_msg);
        }
Esempio n. 4
0
        //Main function parses and sends the messages to server//
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);
            Console.Title = "Server";
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");
            Sender   sndr          = new Sender(Util.makeUrl(srvr.address, srvr.port));
            Receiver rcvr          = new Receiver(srvr.port, srvr.address);
            Action   serviceAction = () => {
                Message msg = null;
                DBEngine <int, DBElement <int, string> > dbserver = new DBEngine <int, DBElement <int, string> >(); //new DBEngine
                QueryEngine QE    = new QueryEngine();
                HiResTimer  timer = new HiResTimer();                                                               //new object for timer
                while (true)
                {
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    Console.Write("\n  Received message:");
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    Console.Write("\n  content is {0}\n", msg.content);
                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n"); continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer"); break;
                    }
                    timer.Start();                  //start timer
                    XElement  insertelem = XElement.Parse(msg.content);
                    XElement  res        = new XElement("result", "not found");
                    processor rdbserver  = new processor();
                    Console.WriteLine("\n----------write client operations----------");
                    Console.WriteLine("\n");
                    //----------select the required method to perform operations------------//
                    if (insertelem.Element("Type").Value.Equals("Insert"))
                    {
                        res = rdbserver.insert(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("Delete"))
                    {
                        res = rdbserver.Delete(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("EditName"))
                    {
                        res = rdbserver.EditName(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("getvalue"))
                    {
                        res = rdbserver.getvalue(insertelem, dbserver, QE);
                    }
                    else if (insertelem.Element("Type").Value.Equals("EditDescr"))
                    {
                        res = rdbserver.editdescr(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("getchildren"))
                    {
                        res = rdbserver.getchildren(insertelem, dbserver, QE);
                    }
                    else if (insertelem.Element("Type").Value.Equals("Persist"))
                    {
                        res = rdbserver.persistdb(insertelem, dbserver);
                    }
                    else
                    {
                        Console.Write("   operation failed   ");
                    }
                    Console.WriteLine("\n-------------server response----------");
                    XElement response = new XElement("resonse");
                    response.Add(res);
                    timer.Stop();              //stop timer
                    Console.WriteLine("the time taken for operation is {0}", timer.ElapsedMicroseconds + " MicroSeconds ");
                    srvr.send_wpf_msg(timer.ElapsedMicroseconds, sndr);
                    Util.swapUrls(ref msg);
                    msg.content = response.ToString();
                    sndr.sendMessage(msg);             //sending message
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous so the call doesn't block.
            }
            Util.waitForUser();
        }
 //Main function parses and sends the messages to server//
 static void Main(string[] args)        {
     Util.verbose = false;
     Server srvr = new Server();
     srvr.ProcessCommandLine(args);
     Console.Title = "Server";
     Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
     Console.Write("\n ====================================================\n");
     Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
     Receiver rcvr = new Receiver(srvr.port, srvr.address);
     Action serviceAction = () =>               {
         Message msg = null;
         DBEngine<int, DBElement<int, string>> dbserver = new DBEngine<int, DBElement<int, string>>(); //new DBEngine
         QueryEngine QE = new QueryEngine();
         HiResTimer timer = new HiResTimer(); //new object for timer
         while (true)                 {
             msg = rcvr.getMessage();   // note use of non-service method to deQ messages
             Console.Write("\n  Received message:");
             Console.Write("\n  sender is {0}", msg.fromUrl);
             Console.Write("\n  content is {0}\n", msg.content);
             if (msg.content == "connection start message")
                 continue; // don't send back start message
             if (msg.content == "done")
             { Console.Write("\n  client has finished\n");continue; }
             if (msg.content == "closeServer")
             {  Console.Write("received closeServer"); break; }
             timer.Start();                  //start timer
             XElement insertelem = XElement.Parse(msg.content);
             XElement res = new XElement("result", "not found");
             processor rdbserver = new processor();
             Console.WriteLine("\n----------write client operations----------");
             Console.WriteLine("\n");
             //----------select the required method to perform operations------------//
             if (insertelem.Element("Type").Value.Equals("Insert"))
                 res = rdbserver.insert(insertelem, dbserver);
                else if (insertelem.Element("Type").Value.Equals("Delete"))
                 res = rdbserver.Delete(insertelem, dbserver);
              else if (insertelem.Element("Type").Value.Equals("EditName"))
                 res = rdbserver.EditName(insertelem, dbserver);
              else if (insertelem.Element("Type").Value.Equals("getvalue"))
                 res = rdbserver.getvalue(insertelem, dbserver, QE);
              else if (insertelem.Element("Type").Value.Equals("EditDescr"))
                 res = rdbserver.editdescr(insertelem, dbserver);
              else if (insertelem.Element("Type").Value.Equals("getchildren"))
                 res = rdbserver.getchildren(insertelem, dbserver, QE);
             else if (insertelem.Element("Type").Value.Equals("Persist"))
                 res = rdbserver.persistdb(insertelem, dbserver);
             else   Console.Write("   operation failed   ");
              Console.WriteLine("\n-------------server response----------");
             XElement response = new XElement("resonse");
             response.Add(res);
             timer.Stop();              //stop timer
             Console.WriteLine("the time taken for operation is {0}", timer.ElapsedMicroseconds + " MicroSeconds ");
             srvr.send_wpf_msg(timer.ElapsedMicroseconds, sndr);
             Util.swapUrls(ref msg);
             msg.content = response.ToString();
             sndr.sendMessage(msg);             //sending message    
               }   };
     if (rcvr.StartService())
     rcvr.doService(serviceAction); // This serviceAction is asynchronous so the call doesn't block.
     Util.waitForUser();        }    }
        //function used to display the performance in WPF
        public void send_wpf_msg(ulong prc_time, Sender sndr)
        {
            Message wpf_msg = new Message();
            wpf_msg.toUrl = "http://localhost:8081/CommService";
            wpf_msg.fromUrl = "http://localhost:8080/CommService";

            string lat_msg = "Server(8080) : Processing time = " + prc_time;
            wpf_msg.content = lat_msg;
            sndr.sendMessage(wpf_msg);

        }
 // main function to send messages
 static void Main(string[] args)         {
     Thread.Sleep(2000);
     Console.Write("\n  starting CommService client");
     Console.Write("\n =============================\n");
     Console.Title = "Client #1";
     Client clnt = new Client();
     clnt.processCommandLine(args);
     string localPort = Util.urlPort(clnt.localUrl);
     string localAddr = Util.urlAddress(clnt.localUrl);
     Receiver rcvr = new Receiver(localPort, localAddr);
     if (rcvr.StartService())            {
         Action newact = clnt.doAction(rcvr);
         rcvr.doService(newact);             }
     Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
     Message msg = new Message();
     msg.fromUrl = clnt.localUrl;
     msg.toUrl = clnt.remoteUrl;
     Console.Write("\n  sender's url is {0}", msg.fromUrl);
     Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);
     if (!sndr.Connect(msg.toUrl))             {
         Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
         sndr.shutdown();
         rcvr.shutDown();                return;            }
     XDocument doc = XDocument.Load("./../../../dbload.xml");
     Console.WriteLine(doc.ToString());
     Console.WriteLine(" xml  is loaded ");
     Console.WriteLine();
     XElement dbe = doc.Element("root");
     int count = Int32.Parse(dbe.Element("count").Value);
     for (int i = 0; i < count; i++)             {
         foreach (var a in dbe.Elements("ClientMessage"))                 {
             msg = new Message();
             msg.fromUrl = clnt.localUrl;
             msg.toUrl = clnt.remoteUrl;
             Console.Write("\n  sending {0}\n", msg.content);
             Console.Write("\n");
             msg.content = a.ToString();
             sndr.sendMessage(msg);
             Thread.Sleep(200);                 }             }
     Thread.Sleep(200);   // Wait for user to press a key to quit.
     // Ensures that client has gotten all server replies.
     Util.waitForUser();   // shut down this client's Receiver and Sender by sending close messages
     rcvr.shutDown();            sndr.shutdown();            Console.Write("\n\n");
 }    } }
    //----< Test Stub >--------------------------------------------------

#if (TEST_SENDER)
    static void Main(string[] args)
    {
      Util.verbose = false;

      Console.Write("\n  starting CommService Sender");
      Console.Write("\n =============================\n");
             Console.Title = "CommService Sender";
              Sender sndr = new Sender("http://localhost:8081/CommService");
             sndr.processCommandLine(args);
             int numMsgs = 5;
      int counter = 0;
      Message msg = null; while (true)  {
        msg = new Message();
        msg.fromUrl = sndr.localUrl;
        msg.toUrl = sndr.remoteUrl;
        msg.content = "Message #" + (++counter).ToString();
        Console.Write("\n  sending {0}", msg.content);
        sndr.sendMessage(msg);
        Thread.Sleep(30);
        if (counter >= numMsgs)
          break;
      }
       msg = new Message();
      msg.fromUrl = sndr.localUrl;
      msg.toUrl = "http://localhost:9999/CommService";
      msg.content = "no listener for this message";
      Console.Write("\n  sending {0}", msg.content);
      sndr.sendMessage(msg);
      msg = new Message();
      msg.fromUrl = sndr.localUrl;
      msg.toUrl = sndr.remoteUrl;
      msg.content = "Message #" + (++counter).ToString();
      Console.Write("\n  sending {0}", msg.content);
      sndr.sendMessage(msg);
      msg = new Message();
      msg.fromUrl = sndr.localUrl;
      msg.toUrl = sndr.remoteUrl;
      msg.content = "closeSender";  // message for self and Receiver
      Console.Write("\n  sending {0}", msg.content);
      sndr.sendMessage(msg);
    }