Beispiel #1
0
    private static void Run()
    {
        while (true)
        {
            string[] input = Console.ReadLine().Split(new char[] { ' ' }, 3);
            switch (input[0])
            {
            case "R":
                ProtocolFunctions.PrintRoutingTable();
                break;

            case "B":
                ProtocolFunctions.MessageService(input[1], input[2]);
                break;

            case "C":
                ProtocolFunctions.NewConnect(int.Parse(input[1]));
                break;

            case "D":
                ProtocolFunctions.DeleteConnect(int.Parse(input[1]));
                break;

            case "Q":
                ProtocolFunctions.TempWriteAllNeighs();
                break;
            }
        }
    }
Beispiel #2
0
    // LET OP: Nadat er verbinding is gelegd, kun je vergeten wie er client/server is (en dat kun je aan het Connection-object dus ook niet zien!)

    // This loop receives messages formatted according to protocol
    public void ReaderThread()
    {
        try
        {
            while (true)
            {
                string test = Read.ReadLine();
                Console.WriteLine("// " + test);
                string[] line = test.Split(new char[] { ' ' }, 3);
                switch (line[0])
                {
                case "Msg":
                    if (int.Parse(line[1]) == NetwProg.myPortNr)
                    {
                        Console.WriteLine(line[2]);
                    }
                    else
                    {
                        ProtocolFunctions.MessageService(line[1], line[2]);
                    }
                    break;

                case "Del":
                    ProtocolFunctions.DeleteConnect(int.Parse(line[1]), false);
                    break;

                case "mdist":
                    string[] lineEx   = line[2].Split(new char[] { ' ' }, 3);
                    int      fromPort = int.Parse(line[1]);
                    int      toPort   = int.Parse(lineEx[0]);
                    int      distance = int.Parse(lineEx[1]);
                    Console.WriteLine("// mdist fromPort: " + fromPort + " toPort: " + toPort + " distance: " + distance);
                    NetChange.DistanceChange(fromPort, toPort, distance);
                    break;
                }
            }
        }
        catch { } // Connection apperently has been closed
    }