コード例 #1
0
        private static void ListenThread(Object threadPasser)
        {
            ThreadPasser tp        = (ThreadPasser)threadPasser;
            TcpClient    clienttmp = tp.client;
            BinaryWriter writer    = new BinaryWriter(clienttmp.GetStream());

            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State = ManagmentProtocol.WHOIS;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            writer.Write(data);

            BinaryReader      reader            = new BinaryReader(clienttmp.GetStream());
            string            received_data     = reader.ReadString();
            JSON              received_object   = JSON.Deserialize(received_data);
            ManagmentProtocol received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();
            String            nodeName          = received_Protocol.Name;

            tp.management.allocateNode(nodeName, clienttmp, Thread.CurrentThread, writer);

            try
            {
                while (true)
                {
                    received_data     = reader.ReadString();
                    received_object   = JSON.Deserialize(received_data);
                    received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();
                    if (received_Protocol.State == ManagmentProtocol.INTERFACEINFORMATION)
                    {
                        UserInterface.showInterfaces(received_Protocol.Interfaces);
                    }
                    if (received_Protocol.State == ManagmentProtocol.GETTABLE)
                    {
                        UserInterface.showTable(received_Protocol.RoutingTable);
                    }
                }
            }
            catch (SocketException e)
            {
                UserInterface.log("Error: " + e.Message, ConsoleColor.Red);
                tp.management.removeNode(nodeName);
            }
            catch (IOException e)
            {
                UserInterface.log("Error: " + e.Message, ConsoleColor.Red);
                tp.management.removeNode(nodeName);
            }
        }
コード例 #2
0
        private static void ListenThread(Object threadPasser)
        {
            ThreadPasser tp        = (ThreadPasser)threadPasser;
            TcpClient    clienttmp = tp.client;
            BinaryWriter writer    = new BinaryWriter(clienttmp.GetStream());

            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State = ManagmentProtocol.WHOIS;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            writer.Write(data);

            BinaryReader      reader            = new BinaryReader(clienttmp.GetStream());
            string            received_data     = reader.ReadString();
            JSON              received_object   = JSON.Deserialize(received_data);
            ManagmentProtocol received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();
            String            nodeName          = received_Protocol.Name;

            tp.control.allocateNode(nodeName, clienttmp, Thread.CurrentThread, writer);
        }
コード例 #3
0
        private void Listen(Object controlP)
        {
            listener.Start();
            ThreadPasser tp = new ThreadPasser();

            tp.control = (ControlPlane)controlP;

            while (run)
            {
                try
                {
                    TcpClient client = listener.AcceptTcpClient();
                    tp.client = client;
                    Thread clientThread = new Thread(new ParameterizedThreadStart(ListenThread));
                    clientThread.Start(tp);
                }
                catch (SocketException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
        }