Check for incoming data
<p>I'm developing a encrypted chatting program that works in LAN it also should be able to send file.here is the problems:
1-For chatting part it only send 1 message and close the connection, the other party should run the program again in order to receive further messages, I tried to put it in a loop like this
(  receive     close   and receive again),    but the program crashed,</p>

<p>I have the same problem for receiving files,<br>
Any idea how can I solve this problem?
This is the code
 IP = textBox2.Text.ToString();
                int port = int.Parse(textBox1.Text);
                IPAddress IP2 = IPAddress.Parse(IP);
                TcpListener TCPListen = new TcpListener(IP2, port);</p>

<pre><code>                TCPListen.Start();

            TcpClient TCP = TCPListen.AcceptTcpClient();
            //bool a = false;

            NetworkStream NetStream = TCP.GetStream();



            //while (!a)
            //{

            RijndaelManaged RMCrypto = new RijndaelManaged();


            byte[] Key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
            byte[] IV = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };




            CryptoStream CryptStream = new CryptoStream(NetStream,
               RMCrypto.CreateDecryptor(Key, IV),
               CryptoStreamMode.Read);

            StreamReader SReader = new StreamReader(CryptStream);




            message = SReader.ReadToEnd();

            textBox3.Clear();

            textBox3.Text = message;

            CryptStream.Flush();

            SReader.Close();


            //encryption(NetStream);




            NetStream.Flush();

            NetStream.Close();

            TCPListen.Stop();
            TCP.Close();
</code></pre>

<p>And it is in a loop like 
  bool a = false;
while(!a)  it means continuously do it.</p>
