Lovemore Kutseya

Lovemore Kutseya

  • NA
  • 21
  • 3.8k

networking scokets c#

Feb 19 2019 3:15 PM
does anybody know how to include the command line arguments of -h, -p. Add the HTTP protocols and the arguments -h0, -h1, -h9.. struggling with this
 
using System;
using System.Net.Sockets;
using System.IO;

namespace location
{
    public class Whois
    {
        static void Main(string[] args)
        {
            try
            {
                TcpClient client = new TcpClient();
                client.Connect("whois.net.dcs.hull.ac.uk", 43);
                StreamWriter sw = new StreamWriter(client.GetStream());
                StreamReader sr = new StreamReader(client.GetStream());


                if (args.Length == 1)
                {
                    sw.WriteLine(args[0]);
                    sw.Flush();
                      
                     string serveresponse = sr.ReadLine();
                     if (serveresponse == ("Error: nothing found"))
                     {
                        Console.WriteLine(serveresponse);
                      }
                      else
                        Console.WriteLine(args[0] + " is " + serveresponse);
                 }
                else if (args.Length == 2)

                {
                    sw.WriteLine(args[0] + " " + args[1]);
                    sw.Flush();
                   
                    if (sr.ReadLine() == ("OK"))
                    {
                        Console.WriteLine(args[0] + " location changed to be " + args[1]);
                    }
                    Console.WriteLine(sr.ReadToEnd());
                }

                else
                {
                    Console.WriteLine("No Arguments Provided");
                }
            }
            catch
            {
                Console.WriteLine("Something Went Wrong");
            }
        }
    }
}
 

Answers (1)