Ejemplo n.º 1
0
        //tests sending a QueryRequest and receiving a response
        static void testQueryRequestClient()
        {
            Guid         myGuid    = Guid.NewGuid();
            TcpClient    tcpClient = new TcpClient("172.18.9.11", 7890);
            ClientThread ct        = new ClientThread(tcpClient, false, myGuid);
            QueryRequest qr        = new QueryRequest(IPAddress.Parse(Node.GetInternetAddress()), myGuid, 777);

            qr.QueryType = QueryType.Hostname;
            ct.EnqueueWork(qr);
            int x = 0;

            while (ct.EventCount() == 0)
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting for response. " + x);
            }
            NetworkResponse response = (NetworkResponse)ct.DequeueEvent();

            Print("response: " + response.Type + " reason: " + response.Reason);
            ct.RequestStop();
            Print("requested stop");
            while (ct.IsAlive())
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting for thread to die. " + x);
            }
            Print("thread dead.");
            Console.WriteLine("press a key to continue");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public static void testSendBackup()
        {
            string       path      = "C:\\Users\\James\\Desktop\\temp\\scratch 2\\How I Met Your Mother Season 06 Episode 24 - Challange Accepted.avi";
            Guid         myGuid    = Guid.NewGuid();
            TcpClient    tcpClient = new TcpClient("172.18.9.11", 7890);
            ClientThread ct        = new ClientThread(tcpClient, false, myGuid);
            PushRequest  pr        = new PushRequest(IPAddress.Parse(Node.GetInternetAddress()), myGuid, 777);

            pr.BackupNumber = 4;
            pr.ChunkNumber  = 5;
            pr.Path         = path;
            pr.FileSize     = new FileInfo(path).Length;
            ct.EnqueueWork(pr);
            int x = 0;

            /*while (ct.EventCount() == 0)
             * {
             *  x++;
             *  Thread.Sleep(1000);
             *  Print("waiting for response. " + x);
             * }
             * NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
             * Print("response: " + response.Type + " reason: " + response.Reason);*/
            while (ct.IsWorking())
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting for thread to finish working. " + x);
            }
            Print("thread finished working. " + x);
            ct.RequestStop();
            Print("requested stop");
            while (ct.IsAlive())
            {
                x++;
                Thread.Sleep(1000);
                Print("waiting for thread to die. " + x);
            }
            Print("thread dead.");
            Console.WriteLine("press a key to continue");
            Console.ReadKey();
        }