Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Enter Server address Enter Server Port Number Get a text file and display to scr

ID: 3862734 • Letter: E

Question

Enter Server address Enter Server Port Number Get a text file and display to screen (using the GET method) Get a text file and save file on the client (using the GET method) Get only the header information of file (using HEAD Method Exit. Menu Options explanation: Program should get the Server address from user using appropriate prompts. Program should get the client port number from user using appropriate prompts. Client should use the GET method to request a file from the server. the program should ask for the file name to get from the server. the Header information sent by server should be displayed on the console. After that, the contents of file are displayed on the screen. You must look up the GET method on Internet to see the appropriate error codes to send to client for various error conditions (such as file not found, etc. Must use appropriate exception handlers). Client should use the GET method to request a file from the server. the program should ask for the file name to get from the server. the Header information sent by server should be displayed on the console. After that, the file is saved to the client computer in the directory from which the program is executed. You must look up the GET method on internet to see the appropriate error codes to send to client for various error conditions (such as file not found, etc. Must use appropriate exception handlers). the client is only requesting Header information using the HEAD method, look up internet to see what information is sent to a browser when HEAD method is requested by client. You may have to look up the MSON information to get those particulars of the file. Exit. Client terminates. After each option (except (f) is executed, the menu appears again and the user can request another client function. Modify the Webserver code so that when the Webserver starts it asks the user for the Port number on which it should run (using an appropriate prompt) and then runs (listens) on that port number. Make the server to not die after serving one client, that is, the server serves one request and then serves the next request, forever (like the server of the TCP Server) Make sure that you test the client and server programs thoroughly. Run the client on several computers and request and send large text files (several MBs each, not just sample one or two-line data files) from the server. Show screenshots of the test results of each menu option and exceptions raised Save the screen shots into one pdf fie and name it lostnomrA2Tesr pdf where Lost Nome is your last name under the LostnameAsstanment2 folder (see below).

Explanation / Answer

First of all, Let me explain you in a step by step manner, how to fulfill all your requirement.:-

a) You need to open Visual studio and create a new project. Select one class and and add the appropriate namespaces like System.Net is neccessary for getting the server address of the User, because it contains IPHostEntry and IPAddress. I have created a program which gives output your ServerAddress.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace ServerAddress
{
class FetchServerAddr
{
static void Main(string[] args)
{
string domainName = Dns.GetHostName();
Console.WriteLine(domainName);
          
string userServerAddr = Dns.GetHostByName(domainName).AddressList[0].ToString();
Console.WriteLine("My Server Address is :"+userServerAddr);
Console.ReadKey();
}
}
}

B) The webserver code is used to fetch and display the Client port number. I have written the program for each respective criteria to have a clear idea about each of them:-

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;

using System.Collections.Generic;
using NetworkCommsDotNet;
namespace port_no

{

class ClientPortNo

{

static void Main(String[] args)

{

Console.WriteLine("Kindly enter port number :");
string machineInfo = Console.ReadLine();

  
string clientIP = machineInfo.Split(':').First();
int clientPort = int.Parse(machineInfo.Split(':').Last());

  
int item = 1;
while (true)
{

string reponseSend = "It is about to send a message " + item ;
Console.WriteLine("The sending message is reponding through server saying '" + reponseSend + "'");

  
NetworkComms.SendObject("Message", clientIP, clientPort, reponseSend);


Console.WriteLine(" Press any key to contiue and q to quit the process !!!");
if (Console.ReadKey(true).Key == ConsoleKey.Q) break;
else item++;
}

  
NetworkComms.Shutdown();
}

}

}

C) The get method to which is just used to view the data in the client browser. I have written a program for the Get method requesting for a server.

using System;
using System.Net;
using System.Text;
using System.IO;


public class GetRequestToServer
{
/
static void Main (string[] args)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create (args[0]);

req.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)req.GetResponse ();

Console.WriteLine ("The Content length for Get Method is {0}", response.ContentLength);
Console.WriteLine ("The Content Type for Get Method is {0}", response.ContentType);

Stream receive = response.GetResponseStream ();

StreamReader readFile = new StreamReader (receive, Encoding.UTF8);

Console.WriteLine (" Successfully Get Method is received.");
Console.WriteLine (readFile.ReadToEnd ());
response.Close ();
readFile.Close ();
}
}

D) The User now can open the file and save it using the proper namespaces for each of them.

using System;
using System.Net;
using System.Text;
using System.IO;

public class GetSaveFileToClient
{
  
static void Main (string[] args)
       {
private static string SaveClientFile(string url)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
ClientResponse res = req.GetResponse();
Stream str = res.GetResponseStream();
StreamReader rd = new StreamReader(str);
return rd.ReadToEnd();
}
}
}