static void Main(string[] args) { WriteRequestParser re = new WriteRequestParser(); Console.Write("\n starting CommService client"); Console.Write("\n =============================\n"); Console.Title = "Write Client"; WriteClient clnt = new WriteClient(); clnt.processCommandLine(args); string localPort = Util.urlPort(clnt.localUrl); string localAddr = Util.urlAddress(clnt.localUrl); Receiver rcvr = new Receiver(localPort, localAddr); if (rcvr.StartService()) { rcvr.doService(rcvr.defaultServiceAction()); } 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; } clnt.request = re.parse("writeRequest.xml"); HiResTimer hrt = new HiResTimer(); ulong total = 0; foreach (string i in clnt.request) { msg = new Message(); msg.fromUrl = clnt.localUrl; msg.toUrl = clnt.remoteUrl; msg.content = i; if (clnt.verbose == 1) { Console.Write("\n Sending: {0}", msg.content); } hrt.Start(); if (!sndr.sendMessage(msg)) { break; } hrt.Stop(); total += hrt.ElapsedMicroseconds; Thread.Sleep(100); } //hrt.Stop(); /*Use the following for testing the client * * int numMsgs = 5; * int counter = 0; * while (true) * { * msg.content = "Hello"; * Console.Write("\n sending {0}", msg.content); * if (!sndr.sendMessage(msg)) * return; * Thread.Sleep(100); ++counter; * if (counter >= numMsgs) * break; * } * */ Console.Write("\n Total time taken for sending all write messages {0} microseconds\n", total); msg = new Message(); msg.fromUrl = clnt.localUrl; msg.toUrl = clnt.remoteUrl; msg.content = "done"; sndr.sendMessage(msg); // 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 try { rcvr.shutDown(); sndr.shutdown(); } catch { Console.Write("\n Problem with closing sender and/or receiver\n"); } Console.Write("\n\n"); }
static void Main(string[] args) { Console.Write("\n starting Write Client for requirement #5"); Console.Write("\n =============================\n"); Console.Title = "WriteClient"; WriteClient clnt = new WriteClient(); clnt.processCommandLine(args); Console.Title = "WriteClient"; string localPort = Util.urlPort(clnt.localUrl); string localAddr = Util.urlAddress(clnt.localUrl); Receiver rcvr = new Receiver(localPort, localAddr); if (rcvr.StartService()) { if(clnt.logMessage == "Yes") rcvr.doService(rcvr.defaultServiceAction()); else rcvr.doService(rcvr.defaultServiceAction2()); } 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; } XmlDocument doc = new XmlDocument(); doc.Load("writeClientTest.xml"); XmlNodeList xmlnode = doc.GetElementsByTagName("Message"); Stopwatch watch = new Stopwatch(); watch.Start();//start watch while (true) { msg = new Message(); msg.fromUrl = clnt.localUrl; msg.toUrl = clnt.remoteUrl; for (int i = 0; i < xmlnode.Count; i++)//read and send message { msg.content = "<?xml version=\"1.0\" encoding=\"utf - 8\" standalone=\"yes\"?>" + xmlnode[i].OuterXml; if(clnt.logMessage == "Yes") Console.Write("\n sending {0}\n", msg.content); if (!sndr.sendMessage(msg)) return; Thread.Sleep(100); } break; } msg.content = "done"; sndr.sendMessage(msg); // Wait for user to press a key to quit. // Ensures that client has gotten all server replies. watch.Stop();//stop watch string time = watch.ElapsedMilliseconds.ToString(); Console.Write("Elapsed time: " + time + " millionsecondns\n\n");//print out time elapsed Util.waitForUser(); // shut down this client's Receiver and Sender by sending close messages rcvr.shutDown(); sndr.shutdown(); Console.Write("\n\n"); }