Exemple #1
0
 static void Main(string[] args)
 {
  try
     {
         Util.verbose = false;
         Server srvr = new Server();
         srvr.ProcessCommandLine(args);
         Console.Title = "Server";
         Console.Write(String.Format("\nStarting CommService server listening on port {0}", srvr.port));
         Console.WriteLine("\nServer Address is {0}", Util.makeUrl(srvr.address, 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 = DefineServiceAction(srvr, sndr, rcvr);
         if (rcvr.StartService())
         {
             rcvr.doService(serviceAction); // This serviceAction is asynchronous, // so the call doesn't block.
         }
         Util.waitForUser();
     }
     catch (CustomException ex)
     {
         Console.WriteLine("Error occured in Server.cs{0}", ex);
     }
 }
Exemple #2
0
 private static Message FinalMessageServe(Server srvr, Sender sndr, Message msg)
 {
     Console.WriteLine("Displaying DB entries");
     srvr.showDB(true, "int");
     Console.Write("\nClient has finished\n");
     Util.swapUrls(ref msg);
     string totalTime = srvr.tot[msg.toUrl].ToString();
     //call the wpf to send message 
     Sender wpfSender = new Sender(Util.makeUrl(srvr.address, srvr.port));
     Message wpfMsg = new Message(); //WPF sender 
     wpfMsg.fromUrl = msg.fromUrl;
     wpfMsg.toUrl = Util.makeUrl(srvr.address, srvr.Wpfport);
     wpfMsg.content = "ServerTime;" + totalTime + ";" + "ClientURL;" + msg.toUrl;
     srvr.tot.Remove(msg.toUrl);
     wpfSender.sendMessage(wpfMsg);
     sndr.sendMessage(msg);       //call the wpf to send message 
     return msg;
 }
Exemple #3
0
 /// <summary>
 /// Proces wheh the response has been received
 /// </summary>
 /// <param name="srvr"></param>
 /// <param name="sndr"></param>
 /// <param name="msg"></param>
 /// <param name="msgid"></param>
 private static void ProcessResponse(Server srvr, Sender sndr, ref Message msg, ref string msgid)
 {
     HiResTimer hres = new HiResTimer(); //High Resolution Timer
     hres.Start();
     XDocument doc = XDocument.Load(new StringReader(msg.content));
     string op = doc.Descendants("Operation").Select(i => i).Single().Value;
     if (op == "Read")
         srvr.ProcessReadMessage(ref msg, ref msgid);
     else
         srvr.ProcessMessage(ref msg, ref msgid);
     hres.Stop();
     Console.WriteLine("Server execution time for processing message(MsgID:{0}) is {1} microseconds \n", msgid, hres.ElapsedMicroseconds);
     Util.swapUrls(ref msg);  // swap urls for outgoing message
     if (srvr.tot.ContainsKey(msg.toUrl))
     {
         ulong x = ulong.Parse(srvr.tot[msg.toUrl].ToString());
         x += hres.ElapsedMicroseconds;
         srvr.tot[msg.toUrl] = x.ToString();
     }
     else
         srvr.tot[msg.toUrl] = hres.ElapsedMicroseconds;
     sndr.sendMessage(msg);
 }
Exemple #4
0
 private static Action DefineServiceAction(Server srvr, Sender sndr, Receiver rcvr)
 {
     Action serviceAction = () =>
     {
         Message msg = null; string msgid = "";
         while (true)
         {
             msg = rcvr.getMessage();   // note use of non-service method to deQ messages
             Console.Write("\nReceived message:");
             Console.Write("\nSender is {0}", msg.fromUrl);
             if (msg.content == "connection start message")
             {
                 Console.Write("\nConnection start message recieved\n");
                 continue; //Don't Send back Start message
             }
             else if (msg.content == "done")
             {
                 msg = FinalMessageServe(srvr, sndr, msg);
                 continue;
             }
             else if (msg.content == "closeServer")
             {
                 Console.Write("Received closeServer");
                 break;
             }
             else
             {
                 ProcessResponse(srvr, sndr, ref msg, ref msgid);
             }
         }
     };
     return serviceAction;
 }