예제 #1
0
        static void Main(string[] args)
        {
            Console.Write("\n  Starting CommService Client");
            Console.Write("\n =============================\n");

            string ServerUrl = "http://localhost:8000/CommService";
            Sender sender    = null;

            Console.Write("\n  Press key to start client: ");
            Console.ReadKey();

            sender = new Sender();
            sender.Connect(ServerUrl);
            sender.Start();

            string   ClientUrl = "http://localhost:8001/CommService";
            Receiver receiver  = new Receiver(ClientUrl);

            // Don't need to start receiver unless you want
            // to send it messages, which we won't as all
            // our messages go to the server
            //receiver.Start();

            EchoCommunicator echo = new EchoCommunicator();

            echo.Name = "client-echo";
            receiver.Register(echo);
            echo.Start();

            ServiceMessage msg1 =
                ServiceMessage.MakeMessage("echo", "ServiceClient", "<root>some echo stuff</root>", "no name");

            msg1.SourceUrl = ClientUrl;
            msg1.TargetUrl = ServerUrl;
            Console.Write("\n  Posting message to \"{0}\" component", msg1.TargetCommunicator);
            sender.PostMessage(msg1);

            ServiceMessage msg2 =
                ServiceMessage.MakeMessage("query", "ServiceClient", "<root>some query stuff</root>", "no name");

            msg2.SourceUrl = ClientUrl;
            msg2.TargetUrl = ServerUrl;
            Console.Write("\n  Posting message to \"{0}\" component", msg2.TargetCommunicator);
            sender.PostMessage(msg2);

            ServiceMessage msg3 =
                ServiceMessage.MakeMessage("nav", "ServiceClient", "<root>some nav stuff</root>", "no name");

            msg3.SourceUrl = ClientUrl;
            msg3.TargetUrl = ServerUrl;
            Console.Write("\n  Posting message to \"{0}\" component", msg3.TargetCommunicator);
            sender.PostMessage(msg3);

            // wait for all server replies to be sent back

            Console.Write("\n  Wait for Server replies, then press a key to exit: ");
            Console.ReadKey();

            sender.Stop(); // this function sends a quit message to client-echo
            sender.Wait();
            echo.Stop();
            echo.Wait();
            receiver.Close();
            Console.Write("\n\n");
        }
 //----< diconnect button >----------------
 private void Disconnect_Click(object sender_, RoutedEventArgs e)
 {
     sender.Stop();
     receiver.Close();
     ShowMsg.Text = "Disconnect with Server!";
 }