I have this code in the server side that processes normal string messages sent by the client. If the client opens an application, the application name will be sent to the server along with its file path and client's hostname. My problem is the server receives only two looped messages, the rest is being attached to the second message. This is the code in the client which sends the message
Code:
 public void sendthedata()
        {
            if (!_timer.Enabled) // If timer is not running send data and start refresh interval
            {
                SendData();
                _timer.Enabled = true;
            }
            else // Stop timer to prevent further refreshing
            {
                _timer.Enabled = false;
            }
        }
        private List<int> listedProcesses = new List<int>();
        private void SendData()
        {
            String processID = "";
            String processName = "";
            String processPath = "";
            String processFileName = "";
            String processMachinename = "";

            listBox1.BeginUpdate();
            try
            {   
                piis = GetAllProcessInfos();
                for (int i = 0; i < piis.Count; i++)
                {
                    try
                    {
                        if (!listedProcesses.Contains(piis[i].Id)) //placed this on a list to avoid redundancy
                        {
                            listedProcesses.Add(piis[i].Id);
                            processID = piis[i].Id.ToString();
                            processName = piis[i].Name.ToString();
                            processPath = piis[i].Path.ToString();
                            processFileName = piis[i].FileName.ToString();
                            processMachinename = piis[i].Machinename.ToString();
                            output.Text += "\n\nSENT DATA : \n\t" + processFileName + "\n\t" + processMachinename + "\n\t" + processID + "\n\t" + processName + "\n\t" + processPath + "\n";
                        }

                    }
                    catch (Exception ex)
                    {
                        wait.Abort();
                        output.Text += "Error..... " + ex.StackTrace;

                    }

                    NetworkStream ns = tcpclnt.GetStream();
                    String data = "";
                    data = "--++" + processFileName + " " +  processMachinename + " "  + processID + " " + processPath;
                    if (ns.CanWrite)
                    {
                        byte[] bf = new ASCIIEncoding().GetBytes(data);
                        ns.Write(bf, 0, bf.Length);
                        ns.Flush();
                    }
                }
            }
            finally
            {
                listBox1.EndUpdate();
            } 
        }
And this is where the server processes the received messages. It passes through the "normal message" part where it has (--++) unicode.

Code:
 private void recieveData()
    {
        NetworkStream nStream = tcpClient.GetStream();
        ASCIIEncoding ascii = null;
        while (!stopRecieving)
        {
            if (nStream.CanRead)
            {
                byte[] buffer = new byte[1024];
                nStream.Read(buffer, 0, buffer.Length);
                ascii = new ASCIIEncoding();
                recvDt = ascii.GetString(buffer);
                /*Received message checks if it has +@@+ then the ip is disconnected*/
                bool f = false;
                f = recvDt.Contains("+@@+");
                if (f)
                {
                    string d = "+@@+";
                    recvDt = recvDt.TrimStart(d.ToCharArray());
                    clientDis();
                    stopRecieving = true;
                }

                //else if (recvDt.Contains("^^"))
                //{
                //    new Transmit_File().transfer_file(file, ipselected);
                //}
                /* ++-- shutsdown/restrt/logoff/abort*/
                else if (recvDt.Contains("++--"))
                {
                    string d = "++--";
                    recvDt = recvDt.TrimStart(d.ToCharArray());
                    this.Invoke(new rcvData(addToOutput));
                    clientDis();
                }
                /*--++ Normal msg*/
                else if (recvDt.Contains("--++"))
                {
                    string d = "--++";
                    recvDt = recvDt.TrimStart(d.ToCharArray());
                    this.Invoke(new rcvData(addToOutput));

                }
            }
            Thread.Sleep(1000);
        }

    }

    public void addToOutput()
    {
        if (recvDt != null && recvDt != "")
        {

            output.Text += "\n Received Data : " + recvDt;
            recvDt = null;


        }

    }
This is an example of a received message. The second "Received Data" gets the rest of the message. I have five opened application in this example. The messages has been assigned a unique character (--++) that will be trimmed when it is being receive in the server. As you can see here the third, fourth and so on messages still has that characters. What seems to be the problem here?



Listening server started @ 192.168.1.101 Listening on 800 port Waiting for connection . . .

New IP client found :192.168.1.101

Received Data : Server_PC UNICORNV-FA15C8 4200 C:\Users\Admin\Desktop\All Client Server and LogIn\LogIn\LogIn2\bin\Debug\LogIn2.vshost.exe

Received Data : Untitled - Notepad UNICORNV-FA15C8 1652 C:\Windows\System32\notepad.exe--++Client_PC (Running) - Microsoft Visual C# 2010 Express UNICORNV-FA15C8 3988 C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\VCSExpress.exe--++LogIn (Running) - Microsoft Visual C# 2010 Express UNICORNV-FA15C8 3756 C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\VCSExpress.exe--++NetworkStream.Read Method (Byte[],?Int32,?Int32)?(System.Net.Sockets) - Google Chrome UNICORNV-FA15C8 2168 C:\Program Files\Google\Chrome\Application\chrome.exe