Esempio n. 1
0
        /// <summary>
        /// Create a command server
        /// </summary>
        /// <param name="sendEndpoint">Endpoint that the server sends messages to</param>
        /// <param name="recvEndpoint">Endpoint that the server receives commands on</param>
        public CommandServer(string sendEndpoint, string recvEndpoint)
        {
            var messageQueueFactory = new MessageQueueFactory();

            _sendQueue = messageQueueFactory.GetWriteOnlyQueue(sendEndpoint);
            _recvQueue = messageQueueFactory.GetReadOnlyQueue(recvEndpoint);
            // receive queue can connect straight away since it waits for incoming
            // connections
            _recvQueue.Connect();
            _listenerThread = new Thread(ListenerLoop);
            _listenerThread.Start();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            const int sendPort = ChatHub.RecvPort;
            const int recvPort = ChatHub.SendPort;

            var closeRequested = false;
            var queueFactory   = new MessageQueueFactory();

            Console.CancelKeyPress += (e, a) =>
            {
                closeRequested = true;
            };

            using (var sendQueue = queueFactory.GetWriteOnlyQueue("tcp://127.0.0.1:" + sendPort))
                using (var recvQueue = queueFactory.GetReadOnlyQueue("tcp://127.0.0.1:" + recvPort))
                {
                    sendQueue.Connect();
                    recvQueue.Connect();
                    while (!closeRequested)
                    {
                        Console.WriteLine("enter a message");
                        var input = Console.ReadLine();
                        sendQueue.Write(input);
                        while (true)
                        {
                            var response = recvQueue.Read();
                            Console.WriteLine("response: " + response);
                            if (response == "END")
                            {
                                break;
                            }
                        }
                    }
                    Console.WriteLine("Shutting down...");
                }
        }