Пример #1
0
        static void Main(string[] args)
        {
            Task t = Task.Factory.StartNew(async () =>
                {
                    Console.WriteLine("Broker...");
                    XMLWorker xmlWorker = new XMLWorker("Reserv.txt");
                    MessageSenderReceiver messageReceiveSend = new MessageSenderReceiver();
                    BinaryWorker bw = new BinaryWorker();
                    MessageChain msg_chain = xmlWorker.readXML();
                    Message m = null;
                    byte[] bytes = null;

                    if (msg_chain != null)
                    {
                        while (true)
                        {
                            m = msg_chain.extract();
                            if (m == null) break;

                            bytes = bw.messageToBytes(m);
                            messageReceiveSend.sendBytesAsync(bytes, m.port);
                            xmlWorker.clear();
                        }
                    }

                    while (true)
                    {
                        bytes = await messageReceiveSend.receiveBytesAsync(30000);
                        m = bw.bytesToMessage(bytes);
                        if (m != null)
                        {
                            MessageChain msg_chain_reserv = new MessageChain();
                            msg_chain_reserv.add(m);
                            xmlWorker.writeXML(msg_chain_reserv);
                        }
                        messageReceiveSend.sendBytesAsync(bytes, m.port);
                        xmlWorker.clear();
                        Console.WriteLine("Message was sent to port " + m.port + "!");
                    }
                });
            t.Wait();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Task t = Task.Factory.StartNew(() =>
                {
                    XMLWorker xmlWorker = new XMLWorker("Send.txt");
                    MessageChain mg_chain = xmlWorker.readXML();
                    Message mg = null;

                    Console.WriteLine("Sender...");
                    while ((mg = mg_chain.extract()) != null)
                    {
                        Console.WriteLine("Press any key to send message!");
                        Console.ReadLine();
                        BinaryWorker bw = new BinaryWorker();
                        byte[] bytes = bw.messageToBytes(mg);
                        MessageSenderReceiver messageSender = new MessageSenderReceiver();
                        messageSender.sendBytesAsync(bytes, 30000);
                    }

                    Console.ReadLine();
                });
            t.Wait();
        }