//----< 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); }
//----< 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"); }