title: TCP Listener receives data in two portions when sent by client in loop
body: <p>In my server client winform app,client sends register request to server..
  in case client is an attacker,he will send that request in loop..for one request it works fine but as i send the same request in loop.my server gets confused and accepts all loop requests data in two portions..1st portion is the first request that is data of one iteration and 2nd portion is the concatinated string of all other say 99 iterations(say client has send data using for loop with 100 iterations).i need to do something which will enforce server to recongnize that where the first request ends and the 2nd begin..and so on.Or is there any way to calculate the time difference between the two portions of data sent by loop..so that i may be able to recognize the attacker and disconnect and black list it's iP to prevent my system from DOS.
  I reviewed msdn asynchronus server and client exaples where EOF is used for this purpose but the problem for loop data is still unsolved.</p>
  
  <p><strong>Readcallback code:</strong></p>
  
  <pre><code>         private void ReadCallback(IAsyncResult result)
              {
                  NetworkStream networkStream = _clientSocket.GetStream();
                  try
                  {
                      int read = networkStream.EndRead(result);
                      if (read == 0)
                      {
                          _networkStream.Close();
                          _clientSocket.Close();
                          return;
                      }
  
                      byte[] buffer = result.AsyncState as byte[];
                      string data = Encoding.Default.GetString(buffer, 0, read);
                      //string[] str = data.Split(new char[] { '~' });
                      //for (int i = 0; i &lt; str.Length; i++)
                      //{
                      arr = data.Split(new char[] { ';' }, 2);
  
  
                      string impi = arr[0];
                      string impu = arr[1];
                      string clientIP = Form1.curIP;
                      //Form1 f1 = new Form1();
                      frm.Output("Data Received:");
                      frm.Output(clientIP + " " + impi + " " + impu);
  
  
  
  
                      /*do the job with the data here*/
  
      }
        catch(exception e)
      {
         throw;
      }
                      //................job.....................
      }
  
  
  **Client Register button:**
  
         private void btnRegister_Click(object sender, EventArgs e)
          {
  
              string data = txtPrivateId.Text + ";" + txtPublicId.Text;
              for (int i = 0; i &lt;100; i++)
              {
                  SendData(data);
              }
              string rec = null;
              rec = ReceiveData();
              txtReceive.Text = rec;
          }
  
  **SendData() code:**
  
       public void SendData(string dataTosend)
          {
              if (string.IsNullOrEmpty(dataTosend))
                  return;
              NetworkStream serverStream = clientSocket.GetStream();
              byte[] outStream = new byte[33];
              outStream = System.Text.Encoding.ASCII.GetBytes(dataTosend);
              serverStream.Write(outStream, 0, outStream.Length);
              serverStream.Flush();
  
  
          }
  </code></pre>
  
  <p>Thank you</p>