static void Main(string[] args) { Task t = Task.Factory.StartNew(async () => { Console.WriteLine("Receiver..."); Console.WriteLine("Input my port number! ^_^"); int port = Convert.ToInt32(Console.ReadLine()); MessageSenderReceiver messageReceiver = new MessageSenderReceiver(); XMLWorker xmlWorker = new XMLWorker("ReceivedMessages.txt"); MessageChain msg_chain = new MessageChain(); //Task<byte[]> bytes = null; BinaryWorker bw = new BinaryWorker(); Message mg = null; while (true) { byte[]bytes = await messageReceiver.receiveBytesAsync(port); mg = bw.bytesToMessage(bytes); msg_chain.add(mg); xmlWorker.writeXML(msg_chain); Console.WriteLine(mg.message); Console.ReadLine(); } }); t.Wait(); }
static void Main(string[] args) { MessageChain mch = new MessageChain(); mch.add(new Message(1, "test1")); mch.add(new Message(2, "test2")); mch.add(new Message(3, "test3")); XMLWorker xmlw = new XMLWorker("test.txt"); xmlw.writeXML(mch); }
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(); }
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(); }