public static void SendMessage(String message) { int poort = Int32.Parse(message.Split()[0]); if (routingtable.containskey(poort)) { routingtable.SendMessage(poort, message); } else { Console.WriteLine("Poort " + poort + " is niet bekend"); } }
static void Main(string[] args) { bool cmdInput = (args.Length != 0); if (cmdInput) { MijnPoort = int.Parse(args[0]); } else { MijnPoort = int.Parse(Console.ReadLine()); } new Server(MijnPoort); Console.Title = "NetChange " + MijnPoort.ToString(); routingtable = new RoutingTable(MijnPoort, new Node(MijnPoort, 0, MijnPoort)); if (cmdInput) { for (int i = 1; i < args.Length; i++) { int newPoort = int.Parse(args[i]); Node newNode = new Node(newPoort, 1, newPoort); bool connectSucceed = false; while (!connectSucceed) { try { AddConnection(newPoort, newNode); connectSucceed = true; Console.WriteLine("Verbonden: " + newPoort); } catch { System.Threading.Thread.Sleep(50); } } } } while (true) { string input = Console.ReadLine(); try { switch (input.Split()[0]) { // R: reveal dictionary case "R": { Print(); break; } // B: bericht naar poort case "B": { input = input.Substring(input.IndexOf(" ") + 1); SendMessage(input); break; } // C: connect met poort case "C": { int poort = int.Parse(input.Split()[1]); Console.WriteLine("Adding connection to {0} in routing table", poort); Node newNode = new Node(poort, 1, poort); AddConnection(poort, newNode); break; } // D: destroy verbinding met poort case "D": { int poort = int.Parse(input.Split()[1]); if (routingtable.containskey(poort)) { Node destroyNode = new Node(poort, 1, poort); routingtable.RemoveConnection(poort, destroyNode); } else { Console.WriteLine("Poort " + poort + " is niet bekend"); } break; } } } catch (Exception e) { Console.WriteLine(e); } } }