void ThreadProc() { tryCount = 0; while (true) { Message msg = sndBlockingQ.deQ(); // out of snd Queue if (msg.destination != currEndpoint) { currEndpoint = msg.destination; while (true) { try { CreateSendChannel(currEndpoint); break; } catch (Exception) { System.Threading.Thread.Sleep(200); } } } while (true) { try { channel.PostMessage(msg); // enQueue to rcver's queue, serverend Console.Write("\n posted message from {0} to {1}", name, msg.destination); tryCount = 0; break; } catch (Exception) { Console.WriteLine("\n connection failed, reconnecting..."); if (++tryCount < MaxCount) { System.Threading.Thread.Sleep(100); } else { Console.WriteLine("\n {0}", "can't connect"); currEndpoint = ""; tryCount = 0; break; } } } if (msg.body == "quit") { break; } } }
protected override void ProcessMessages() { while (true) { ServiceMessage msg = bq.deQ(); if (msg.TargetUrl != currentUrl) { Console.Write("\n connecting to {0}", msg.TargetUrl); this.Connect(msg.TargetUrl); currentUrl = msg.TargetUrl; } svc.PostMessage(msg); if (msg.TargetCommunicator == this.Name && msg.Contents == "quit") { break; } } }