public void sendthedata(){ if (!_timer.Enabled) // If timer is not running send data and start refresh interval{ SendData(); _timer.Enabled = true; } private List<int> listedProcesses = new List<int>();else // Stop timer to prevent further refreshing { _timer.Enabled = false; } } String processPath = "";private void SendData() { String processID = ""; String processName = ""; String processFileName = ""; for (int i = 0; i < piis.Count; i++)String processMachinename = ""; listBox1.BeginUpdate(); try { piis = GetAllProcessInfos(); { try { processID = piis[i].Id.ToString();if (!listedProcesses.Contains(piis[i].Id)) //placed this on a list to avoid redundancy { listedProcesses.Add(piis[i].Id); processName = piis[i].Name.ToString(); output.Text += "\n\nSENT DATA : \n\t" + processFileName + "\n\t" + processMachinename + "\n\t" + processID + "\n\t" + processName + "\n\t" + processPath + "\n";processPath = piis[i].Path.ToString(); processFileName = piis[i].FileName.ToString(); processMachinename = piis[i].Machinename.ToString(); } } catch (Exception ex) { wait.Abort(); data = "--++" + processFileName + " " + processMachinename + " " + processID + " " + processPath;output.Text += "Error..... " + ex.StackTrace; } NetworkStream ns = tcpclnt.GetStream(); String data = ""; if (ns.CanWrite) { byte[] bf = new ASCIIEncoding().GetBytes(data); ns.Write(bf, 0, bf.Length); ns.Flush(); } } } }finally { listBox1.EndUpdate(); }
private void recieveData(){ NetworkStream nStream = tcpClient.GetStream();ASCIIEncoding ascii = null; byte[] buffer = new byte[1024];while (!stopRecieving) { if (nStream.CanRead) { ascii = new ASCIIEncoding();nStream.Read(buffer, 0, buffer.Length); recvDt = ascii.GetString(buffer); f = recvDt.Contains("+@@+");/*Received message checks if it has +@@+ then the ip is disconnected*/ bool f = false; if (f) { string d = "+@@+"; // new Transmit_File().transfer_file(file, ipselected);recvDt = recvDt.TrimStart(d.ToCharArray()); clientDis(); stopRecieving = true; } //else if (recvDt.Contains("^^")) //{ //} this.Invoke(new rcvData(addToOutput));/* ++-- shutsdown/restrt/logoff/abort*/ else if (recvDt.Contains("++--")) { string d = "++--"; recvDt = recvDt.TrimStart(d.ToCharArray()); clientDis(); } Thread.Sleep(1000);/*--++ Normal msg*/ else if (recvDt.Contains("--++")) { string d = "--++"; recvDt = recvDt.TrimStart(d.ToCharArray()); this.Invoke(new rcvData(addToOutput)); } } } } }public void addToOutput() { if (recvDt != null && recvDt != "") { output.Text += "\n Received Data : " + recvDt; recvDt = null; }