C# Server And client
**Hello, 
I Had been working on a simple server/client
but there was a problem i couldn't type 2 messages after each others on one cmd (client/server) so i made a timer with the send/receive command but when i start it it stops in the same seconds**

***Here is the Server's Code***

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Timers;
    
        namespace Server
        {
            class Program
            {
                //--------------------------------------------------------------------------------------------
                static TcpClient connected;
                //--------------------------------------------------------------------------------------------
                static void Main(string[] args)
                {
                    TcpListener listener = new TcpListener(IPAddress.Any, 1980);
                    
                    listener.Start();
                    connected = listener.AcceptTcpClient();
        
                    System.Timers.Timer timer = new System.Timers.Timer();
                    timer.Elapsed += new ElapsedEventHandler(timerTick);
                    timer.Interval = 100;
        
                    Thread.Sleep(1000);
                    timer.Enabled = true;
                }
                //--------------------------------------------------------------------------------------------
                static byte[] buffer = new byte[4096];
                //--------------------------------------------------------------------------------------------
                static void send()
                {
                 
                    NetworkStream stream = connected.GetStream();
                    byte[] data = Encoding.ASCII.GetBytes(Console.ReadLine());
                    stream.Write(data, 0, data.Length);
                    send();
                }
                //--------------------------------------------------------------------------------------------
                public static void timerTick(object source, ElapsedEventArgs e)
                {
                        receive();
                        
                }
                //--------------------------------------------------------------------------------------------
                static void sendCP()
                {
        
                    NetworkStream stream = connected.GetStream();
                    byte[] data = Encoding.ASCII.GetBytes("Connected To Server");
                    stream.Write(data, 0, data.Length);
        
                }
        
          
        
                static void receive()
                {
                    NetworkStream stream = connected.GetStream();
                    int data = stream.Read(buffer, 0, 4096);
                    string rec = Encoding.ASCII.GetString(buffer, 0, data);
        
                    Console.WriteLine("Client: " + Encoding.ASCII.GetString(buffer, 0, data));
                    for (; ; ) { }
                }
            }
        }


***This is the Client's Code***

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Timers;
    namespace Client
    {
        class Program
        {
            static TcpClient client;
    
            static void Main(string[] args)
            {
              System.Timers.Timer timer = new System.Timers.Timer();
              timer.Elapsed += new ElapsedEventHandler(timerTick);
              timer.Interval = 1000;
              client = new TcpClient();
                client.Connect("127.0.0.1", 1980);
                if (client.Connected)
                {
                    sendCP();
                    timer.Enabled = true;
                }
            }
            public static void timerTick(object source,ElapsedEventArgs e)
            {
                while (client.Connected)
                {
                    receive();
                }
            }
            static byte[] buffer = new byte[4096];
            static void send()
            {
             
                NetworkStream stream = client.GetStream();
                byte[] data = Encoding.ASCII.GetBytes(Console.ReadLine());
                stream.Write(data, 0, data.Length);
                send();
            }
            static void sendCP()
            {
    
                NetworkStream stream = client.GetStream();
                byte[] data = Encoding.ASCII.GetBytes("Connected To Client");
                stream.Write(data, 0, data.Length);
            }
            static void receive()
            {
                NetworkStream stream = client.GetStream();
                int data = stream.Read(buffer, 0, 4096);
                string rec = Encoding.ASCII.GetString(buffer, 0, data);
                Console.WriteLine("Server: " + Encoding.ASCII.GetString(buffer, 0, data));
            }
        }
    }

***Hope Anybody Could Help me and Thanks!***

C# Server And client
===

**Hello, 
I Had been working on a simple server/client
but there was a problem i couldn't type 2 messages after each others on one cmd (client/server) so i made a timer with the send/receive command but when i start it it stops in the same seconds**

***Here is the Server's Code***

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Timers;
    
        namespace Server
        {
            class Program
            {
                //--------------------------------------------------------------------------------------------
                static TcpClient connected;
                //--------------------------------------------------------------------------------------------
                static void Main(string[] args)
                {
                    TcpListener listener = new TcpListener(IPAddress.Any, 1980);
                    
                    listener.Start();
                    connected = listener.AcceptTcpClient();
        
                    System.Timers.Timer timer = new System.Timers.Timer();
                    timer.Elapsed += new ElapsedEventHandler(timerTick);
                    timer.Interval = 100;
        
                    Thread.Sleep(1000);
                    timer.Enabled = true;
                }
                //--------------------------------------------------------------------------------------------
                static byte[] buffer = new byte[4096];
                //--------------------------------------------------------------------------------------------
                static void send()
                {
                 
                    NetworkStream stream = connected.GetStream();
                    byte[] data = Encoding.ASCII.GetBytes(Console.ReadLine());
                    stream.Write(data, 0, data.Length);
                    send();
                }
                //--------------------------------------------------------------------------------------------
                public static void timerTick(object source, ElapsedEventArgs e)
                {
                        receive();
                        
                }
                //--------------------------------------------------------------------------------------------
                static void sendCP()
                {
        
                    NetworkStream stream = connected.GetStream();
                    byte[] data = Encoding.ASCII.GetBytes("Connected To Server");
                    stream.Write(data, 0, data.Length);
        
                }
        
          
        
                static void receive()
                {
                    NetworkStream stream = connected.GetStream();
                    int data = stream.Read(buffer, 0, 4096);
                    string rec = Encoding.ASCII.GetString(buffer, 0, data);
        
                    Console.WriteLine("Client: " + Encoding.ASCII.GetString(buffer, 0, data));
                    for (; ; ) { }
                }
            }
        }


***This is the Client's Code***

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Timers;
    namespace Client
    {
        class Program
        {
            static TcpClient client;
    
            static void Main(string[] args)
            {
              System.Timers.Timer timer = new System.Timers.Timer();
              timer.Elapsed += new ElapsedEventHandler(timerTick);
              timer.Interval = 1000;
              client = new TcpClient();
                client.Connect("127.0.0.1", 1980);
                if (client.Connected)
                {
                    sendCP();
                    timer.Enabled = true;
                }
            }
            public static void timerTick(object source,ElapsedEventArgs e)
            {
                while (client.Connected)
                {
                    receive();
                }
            }
            static byte[] buffer = new byte[4096];
            static void send()
            {
             
                NetworkStream stream = client.GetStream();
                byte[] data = Encoding.ASCII.GetBytes(Console.ReadLine());
                stream.Write(data, 0, data.Length);
                send();
            }
            static void sendCP()
            {
    
                NetworkStream stream = client.GetStream();
                byte[] data = Encoding.ASCII.GetBytes("Connected To Client");
                stream.Write(data, 0, data.Length);
            }
            static void receive()
            {
                NetworkStream stream = client.GetStream();
                int data = stream.Read(buffer, 0, 4096);
                string rec = Encoding.ASCII.GetString(buffer, 0, data);
                Console.WriteLine("Server: " + Encoding.ASCII.GetString(buffer, 0, data));
            }
        }
    }

***Hope Anybody Could Help me and Thanks!***
