Example #1
0
 private void requestButton_Click(object sender, EventArgs e)
 {
     try
     {
         string        file          = filePathBox.Text;
         RequestHeader clientHeader  = new GetRequestHeader(file, Program.client.key);
         byte[]        requestHeader = clientHeader.ReturnRawHeader();
         Program.client.SendHeader(requestHeader);
         Program.client.stream.Flush();
         messageBox.Text = Program.client.HandleResponse(false, file).Value;
     }
     catch (Exception ex)
     {
         messageBox.Text = ex.Message;
     }
 }
Example #2
0
        public void HandleFailureTest()
        {
            Client        testClient = new Client();
            RequestHeader testHeader = new GetRequestHeader("cheese.txt", testClient.key);

            testClient.Connect("127.0.0.1", 9001);
            testClient.SendHeader(testHeader.ReturnRawHeader());
            if (testClient.HandleResponse(false, "cheese.txt").Key == 0)
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
Example #3
0
        public void SendResponseTest()
        {
            //Test to make sure that responses are successfully sent to the client

            Client         testClient   = new Client();
            RequestHeader  testHeader   = new GetRequestHeader("cheese.txt", testClient.key);
            ResponseHeader testResponse = new ResponseHeader();

            testClient.Connect("127.0.0.1", 9001);
            testClient.SendHeader(testHeader.ReturnRawHeader());
            if (testClient.HandleResponse(false, "cheese.txt").Key == 0)
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
Example #4
0
        public void HandleRequestTest()
        {
            //Test to make sure that requests are successfully handled

            Client         testClient   = new Client();
            RequestHeader  testHeader   = new GetRequestHeader("cheese.txt", testClient.key);
            ResponseHeader testResponse = new ResponseHeader();
            ResponseHeader failResponse = new ResponseHeader(2, Encoding.UTF8.GetBytes("Bad header received"));

            testClient.Connect("127.0.0.1", 9001);
            testClient.SendHeader(testHeader.ReturnRawHeader());
            if (testResponse == failResponse)
            {
                Assert.Fail();
            }
            else
            {
                Assert.Pass();
            }
        }