private void getConnectionRequestMsg(String msg) { try { String ip; String port; String name; String cpu; Thread t1 = null; Thread t2 = null; Thread t3 = null; XDocument xml = XDocument.Parse(msg); var q = from x in xml.Elements("root").Descendants() select x; foreach (var elem in q) { ip = elem.Attributes().ElementAt(0).Value; port = elem.Attributes().ElementAt(1).Value; name = elem.Attributes().ElementAt(2).Value; cpu = elem.Attributes().ElementAt(3).Value; if (IPtoPeer.Count > 0) { if (!NametoIP.Contains(name)) { InsertPeer(ip, port, name, cpu); if (IPtoPeer.Count == 2) SetBackup(ip + ":" + port); MessageGenerator temp = new MessageGenerator(); string mMsg = temp.msgIPtoPeer(IPtoPeer); string master = temp.msgMaster(GetMaster()); string backup = temp.msgBackup(GetBackup()); AsynchronousClient client1 = new AsynchronousClient(); client1.SetMultiMsg(IPtoPeer, mMsg, mPeer.mIP + ":" + mPeer.mPort); t1 = new Thread(new ThreadStart(client1.SendMultiClient)); t1.IsBackground = true; t1.Start(); AsynchronousClient client2 = new AsynchronousClient(); client2.SetSingleMsg(ip, port, master); t2 = new Thread(new ThreadStart(client2.SendSingleClient)); t2.IsBackground = true; t2.Start(); AsynchronousClient client3 = new AsynchronousClient(); client3.SetSingleMsg(ip, port, backup); t3 = new Thread(new ThreadStart(client3.SendSingleClient)); t3.IsBackground = true; t3.Start(); } else { MessageGenerator temp = new MessageGenerator(); string error = temp.msgError("10:Username Already Exists"); AsynchronousClient client = new AsynchronousClient(); client.SetSingleMsg(ip, port, error); t1 = new Thread(new ThreadStart(client.SendSingleClient)); t1.IsBackground = true; t1.Start(); } } else { MessageGenerator temp = new MessageGenerator(); string error = temp.msgError("10:Peer is not a part of Swarm"); AsynchronousClient client = new AsynchronousClient(); client.SetSingleMsg(ip, port, error); t1 = new Thread(new ThreadStart(client.SendSingleClient)); t1.IsBackground = true; t1.Start(); } } showTable(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }