0

I need to connect over a clear TCP socket connection with a defined IP and port, that is used as an argument when the program is ran. Then once it is connected I need to send a command through and then get a response back from the server. Are there any good tutorials for C# out there for this? All I could find were ones that had port and IP set within the program.

SO I got some of it working, but can't get the input from command line. I need to send data that is inputted and the return a response.

 TcpClient client = new TcpClient(hostName, portNumber);
 StreamReader sr = new StreamReader(client.GetStream());
 StreamWriter sw = new StreamWriter(client.GetStream());
 String data = sr.ReadLine();

 while (data != null)
        {

              sw.WriteLine(data);
              data = sr.ReadLine();
            Console.WriteLine("\nSend: " + data);
            }
user3772253
  • 53
  • 1
  • 6
  • http://stackoverflow.com/questions/6151036/console-app-arguments-how-arguments-are-passed-to-main-method pass the arugments and do the connection programmatically – Gabe Feb 18 '16 at 02:53
  • Can't you take those examples,create a program,pass arguments and replace the hardcoded port,IP with arguments? – nobody Feb 18 '16 at 02:55
  • I am new to C#, so I didn't know exactly how it worked with arguments and running it from the command line. Thanks! – user3772253 Feb 18 '16 at 03:56
  • And also, the part I am more stuck on is it reading the command and then sending a response correlated to that command. – user3772253 Feb 18 '16 at 03:59
  • Add a switch in your code that recognises the command(s) you place in the arguments, then process it as required. If you're asking for actual code, it's unlikely you'll get a full solution here - SO isn't about that. But if you try it and it doesn't work, come back and post the code and ask a [solid question](http://stackoverflow.com/help/how-to-ask), then you'll likely get a much more enthusiastic response. – Gabe Feb 18 '16 at 05:14

0 Answers0