title: Listening data over TCP/Ip and then Writing data into File as XML
body: <p>Our Client have a dialysis machine which use Ethernet TCP/IP Protocol and data transfer protocol is XML.It automatically connects to the our
  computer system by using the configured IP address and port number and sends unsolicited data messages every 60 seconds to our system. Client send data as XML Data Stream. Now I need to store data in XML file.</p>
  <p>For above requirement I developed a TCP/IP listener(.exe) as destop app. Below is code:</p>
  <pre><code>        server = new TcpListener(localAddr, port);
          server.Start();
          while (true)
          {
              string FileName = &quot;NiproMI&quot; + DateTime.Now.ToString().Replace(&quot; &quot;,&quot;_&quot;) + &quot;.xml&quot;;
              NiproEventsLog.WriteLog(FileName);
              NiproEventsLog.WriteLog(&quot;Waiting for a connection... &quot;);
              TcpClient client = server.AcceptTcpClient();
              NiproEventsLog.WriteLog(&quot;Connected!&quot;);
              NetworkStream stream = client.GetStream();
              StreamReader sr = new StreamReader(stream);
              string fileContent = sr.ReadToEnd();
              File.WriteAllText(Path.Combine(GetAppConfigValues.GetAppConfigValue(&quot;XmlFilePath&quot;), FileName), fileContent);
              client.Close();
          }
              
  </code></pre>
  <p>Is this right way or is there is any better way?
  kindly help.</p>