//----< Test Stub >-------------------------------------------------- #if (TEST_RECEIVER) static void Main(string[] args) { Util.verbose = true; Console.Title = "CommService Receiver"; Console.Write("\n Starting CommService Receiver"); Console.Write("\n ===============================\n"); Receiver rcvr = new Receiver(); rcvr.ProcessCommandLine(args); Console.Write("\n Receiver url = {0}\n", Util.makeUrl(rcvr.address, rcvr.port)); // serviceAction defines what the server does with received messages if (rcvr.StartService()) { //rcvr.doService(); rcvr.doService(rcvr.defaultServiceAction()); // equivalent to rcvr.doService() } Console.Write("\n press any key to exit: "); Console.ReadKey(); Console.Write("\n\n"); }
//----< get Receiver and Sender running >---------------------------- void setupChannel() { rcvr = new Receiver(localPort, localAddress); Action serviceAction = () => { try { Message rmsg = null; while (true) { rmsg = rcvr.getMessage(); //Action act = () => { postRcvMsg(rmsg.content); }; Action act = () => { processRcvMsg(rmsg); }; Dispatcher.Invoke(act, System.Windows.Threading.DispatcherPriority.Background); } } catch(Exception ex) { Action act = () => { lStat.Text = ex.Message; }; Dispatcher.Invoke(act); } }; if (rcvr.StartService()) { rcvr.doService(serviceAction); } sndr = new wpfSender(lStat, this.Dispatcher); }
//----< Entry point for 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); srvr.CalculatePerf(); // - serviceAction defines what the server does with received messages // - This serviceAction just announces incoming messages Action serviceAction = () => { Message msg = null; 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 Request ID: {0}\n", msg.messageID); Console.Write("\n content is {0}\n", msg.content); if (msg.content == "connection start message") { Console.Write("\n client connected\n"); continue; } else if (msg.content == "done") { Console.Write("\n client has finished\n"); continue; } else if (msg.content == "closeServer") { Console.Write("received closeServer"); break; } else if (msg.type == 0) { sndr.sendMessage(srvr.ProcessQuery(msg)); } else if (msg.type == 1) { sndr.sendMessage(srvr.ProcessAddKey(msg)); } else if (msg.type == 2) { sndr.sendMessage(srvr.ProcessRmvKey(msg)); } else if (msg.type == 3) { sndr.sendMessage(srvr.ProcessGetValue(msg)); } else if (msg.type == 4) { sndr.sendMessage(srvr.ProcessEditKey(msg)); } else if (msg.type == 5) { sndr.sendMessage(srvr.ProcessDBDisplay(msg)); } else if (msg.type == 6) { sndr.sendMessage(srvr.ProcessPersist(msg)); } else if (msg.type == 7) { sndr.sendMessage(srvr.ProcessRestore(msg)); } else if (msg.type == 8) { sndr.sendMessage(srvr.ProcessTypeReq(msg)); } msg.content = "received " + msg.content + " from " + msg.fromUrl; Util.swapUrls(ref msg); } }; if (rcvr.StartService()) { rcvr.doService(serviceAction); // This serviceAction is asynchronous so the call doesn't block. } Util.waitForUser(); }
//----< Test Stub >-------------------------------------------------- static void Main(string[] args) { Util.verbose = true; Console.Title = "CommService Receiver"; Console.Write("\n Starting CommService Receiver"); Console.Write("\n ===============================\n"); Receiver rcvr = new Receiver(); rcvr.ProcessCommandLine(args); Console.Write("\n Receiver url = {0}\n", Util.makeUrl(rcvr.address, rcvr.port)); // serviceAction defines what the server does with received messages if (rcvr.StartService()) { //rcvr.doService(); rcvr.doService(rcvr.defaultServiceAction()); // equivalent to rcvr.doService() } Console.Write("\n press any key to exit: "); Console.ReadKey(); Console.Write("\n\n"); }