title: c# tcpclient program writing to stream but client not receiving data
body: <p>I have written a <strong>TCPClient</strong> program to run on my PC. It first initiates a TCP listener to listen on a specific port then reads/writes from/to multiple TCP clients on multiple threads.<br>
  I am able to read from the client but whenever I try to send data to it, the program displays that it has sent the data, but the client does not receive anything. </p>
  
  <p>Here's the code:  </p>
  
  <pre><code>            TcpClient client = listener.AcceptTcpClient();
              var childSocketThread = new Thread(() =&gt;
              {
                  if (client.Connected)
                  {
                      using (NetworkStream stream = client.GetStream())
                   {
                      Console.WriteLine("connected");
                      byte[] data = new byte[1000];
                      try
                      {
                          if (stream.CanRead)
                          {
                              stream.Read(data, 0, 1000);
                              string dataStr = Encoding.ASCII.GetString(data);
                              string dataa = dataStr.TrimEnd('\0');
                              //Console.WriteLine(dataa);
                              if (dataa.Length &gt; 10)
                              {
                                  deviceid = ParseRequest(dataa);
  
                                  byte[] sendnow = Encoding.ASCII.GetBytes(reply[deviceid]);
  
                                  Array.Clear(data, 0, 1000);
                                  Console.WriteLine("Recieved data: " + dataa);
                                  Console.WriteLine("Sending data");
                                  using (StreamWriter writer = new StreamWriter(stream))
                                  {
                                      writer.AutoFlush = true;
                                      writer.WriteLine(reply[deviceid]);
                                  }
                                  Console.WriteLine(reply[deviceid]);
                                  Console.WriteLine("Sent");
                              }
  
                              Console.WriteLine();
                          }
                      }
                      catch (Exception es)
                      {
                          Console.WriteLine(es);
                      }
                   }
                  }
  
              });
              childSocketThread.Start();    
  </code></pre>
  
  <p>The server device that I am using is a PLC. Also, things I have already tried:<br>
  1) sending directly using Socket.Send method.<br>
  2) sending directly using NetworkStream method.<br>
  3) accepting the TCP connection as sockets. (<code>Socket device = listener.AcceptSocket</code>).   </p>
  
  <p>None of these methods seem to send to the device, even though the program tells me that it had no issues sending data since it displays "Sent" after attempting to send data. 
  I downloaded another program from this link <a href="http://www.codeproject.com/Articles/488668/Csharp-TCP-Server" rel="nofollow noreferrer">http://www.codeproject.com/Articles/488668/Csharp-TCP-Server</a>. The test app they provide with it is able to send and receive data on the same port as my program running on the same PC.</p>
  
  <p>I haven't been able to get any direction on how to diagnose and more importantly solve this issue. Any ideas?</p>
  
  <p><strong>Update 2015-08-10 11:18 a.m.:</strong><br>
  Output of the Program is as follows:
  <a href="https://i.stack.imgur.com/mK3zH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mK3zH.png" alt="enter image description here"></a></p>
  
  <p><strong>Update 2015-08-10 11:32 a.m.:</strong><br>
  Output of Syslog Console:
  <a href="https://i.stack.imgur.com/jx9sb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jx9sb.png" alt="enter image description here"></a></p>
  
  <p><strong>Update 2015-08-10 12:07 p.m.:</strong><br>
  Output of Wireshark:<br>
  <a href="https://i.stack.imgur.com/FsRoK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FsRoK.png" alt="enter image description here"></a></p>