Пример #1
0
        static void Main(string[] args)
        {
            IMessagingSystemFactory     messagingSystemFactoryTCP = new TcpMessagingSystemFactory();
            DuplexStringMessagesFactory aReceiverFactory          = new DuplexStringMessagesFactory();

            myStringReceiver = aReceiverFactory.CreateDuplexStringMessageReceiver();
            // Subscribe to get notified when a client connects, disconnects
            // or sends a message.

            myStringReceiver.RequestReceived           += OnMessageReceived;
            myStringReceiver.ResponseReceiverConnected += OnConnect;
            IMessagingSystemFactory stringMessaging = new TcpMessagingSystemFactory()
            {
                // Set to receive messages in the main UI thread.
                // Note: if this is not set then methods OnMessageReceived, OnClientConnected
                //       and OnClientDisconnected would not be called from main UI thread
                //       but from a listener thread.
                MaxAmountOfConnections = 5
            };

            // Create input channel.
            IDuplexInputChannel aInputChannel = stringMessaging.CreateDuplexInputChannel("tcp://192.168.1.5:8061/");

            // Attach the input channel and be able to receive messages
            // and send back response messages.
            myStringReceiver.AttachDuplexInputChannel(aInputChannel);



            IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory();



            // Use authenticated connection.
            IMessagingSystemFactory aMessaging =
                new AuthenticatedMessagingFactory(aTcpMessaging, GetHandshakeMessage, Authenticate);
            IDuplexInputChannel anInputChannel =
                aMessaging.CreateDuplexInputChannel("tcp://192.168.1.5:8060/");

            // Use simple text messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();

            myReceiver = aStringMessagesFactory.CreateDuplexStringMessageReceiver();
            myReceiver.RequestReceived += OnRequestReceived;

            // Attach input channel and start listening.
            // Note: the authentication sequence will be performed when
            //       a client connects the service.
            myReceiver.AttachDuplexInputChannel(anInputChannel);

            Console.WriteLine("Service is running. Press Enter to stop.");
            Console.ReadLine();

            // Detach input channel and stop listening.
            // Note: tis will release the listening thread.
            myReceiver.DetachDuplexInputChannel();
        }
        public void StopServer()
        {
            // Close listenig.
            // Note: If the listening is not closed, then listening threads are not ended
            //       and the application would not be closed properly.
            CommandReceiver.DetachDuplexInputChannel();
            Worker4504InputChannel.StopListening();

            myPolicyServer.StopPolicyServer();
        }
 public void DetachDuplexInputChannel()
 {
     string_receiver_.DetachDuplexInputChannel();
 }