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

namespace TCPClientStreamWriter
{
    class Program
    {
        static void Main(string[] args)
        {
            string data;
            string input;
            IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12537);
           // IPEndPoint ipep = new IPEndPoint(Dns.Resolve(Dns.GetHostName()).AddressList[0], 2009);
            Socket server = new Socket(ipep.AddressFamily,
                            SocketType.Stream, ProtocolType.Tcp);
            try
            {
                server.Connect(ipep);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Unable to connect to server.");
                Console.WriteLine(e.ToString());
                return;
            }

            NetworkStream ns = new NetworkStream(server);
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);
            sw.WriteLine("LED ON");
            sw.Flush();
            Console.WriteLine("request sent");
            Console.WriteLine("receiving acknoledge from server");
            data = sr.ReadLine();
            Console.WriteLine(data);
            sr.Close();
            sw.Close();
            ns.Close();
            server.Shutdown(SocketShutdown.Both);
            server.Close();
            Console.WriteLine("Disconnecting from server...");
            Console.ReadKey();
        }
    }
}
