title: updating data via sockets in c#
body: <p>i've got a server with all the logic of a four on row game of which i would like to display the state  after each player turn i've got several class and i would like to send the game with the position played each turn,i succeded to send the first move to the client but the client just shoot down after that. the client and the server are both console application 
  in my main server side i've got this</p>
  
  <pre><code>var game = Game.CreateConsoleGame(DifficultyLevel.Hard, ActivePlayer.User, false);
              game.Play();
              Console.ReadKey();
  </code></pre>
  
  <p>those line are going to use other class Board,Game,Iodevice,judge and player
  making all the logic of the game
  in class player i've got this</p>
  
  <p>and once i've got the position played ,i draw a String Builder
  with this method</p>
  
  <pre><code>public static StringBuilder DrawStringBuilder(int nk)
              {
  
                  cells = new CellStates[6, 7];
  
                  var builder = new StringBuilder();
                  var header = "  0        1         2         3        4        5         6";
                  var divisor = "-------------------------------------------------------------------";
                  builder.AppendLine(header);
                  builder.AppendLine(divisor);
  
                  int p = 0;
                  for (int i = 0; i &lt; cells.GetLength(0); i++)
                  {
  
                      for (int j = 0; j &lt; cells.GetLength(1); j++)
                      {
  
                          int counter1 = 0;
                          int counter2 = 1;
                          cells[5, nk] = CellStates.Player;
                          //cells[5, 0] = CellStates.User;
                          var str = cells[i, j] == CellStates.Empty ? "| ······· " : (cells[i, j] == CellStates.User ? "|     0   " : "|   x     ");
  
                          builder.Append(str);
                          counter1 = counter1 + 2;
                          counter2++;
  
                      }
  
  
  
                      builder.Append('|');
                      builder.AppendLine();
                      builder.AppendLine(divisor);
  
  
  
                  }
                  return builder;
              }
  </code></pre>
  
  <p>i am just using this method 
  to send it to the client </p>
  
  <pre><code>  public static void SendingPacket(StringBuilder packet)
              {
                  IPAddress ipLocal;
                  IPEndPoint ipeLocal;
                  TcpListener List;
                  TcpClient tc = null;
                  NetworkStream ns = null;
                  string s2;
  
                  int n = 0;
                  try
                  {
                      ipLocal = IPAddress.Parse("127.0.0.1");
                      ipeLocal = new IPEndPoint(ipLocal, 8888);
                      List = new TcpListener(ipeLocal);
  
  
                      List.Start();
                      tc = List.AcceptTcpClient();
  
                      ns = tc.GetStream();
                      StreamReader reader = new StreamReader(ns);
                      StreamWriter write = new StreamWriter(ns);
                      string response = null;
                      //Console.WriteLine(response);
  
  
                      response = reader.ReadLine();
                      Console.WriteLine(response);
                      Thread.Sleep(200);
                      write.WriteLine(packet);
                      write.Flush();
                      n++;
  
  
  
  
  
                      Console.WriteLine("j'envoie");
                      Console.WriteLine("de player");
                      Console.ReadKey();
                  }
                  catch (Exception ex)
                  {
  
                      Console.WriteLine(ex.Message);
                  }
                  finally
                  {
                      if ((tc != null) &amp;&amp; (ns != null))
                      {
                          tc.Close();
                          ns.Close();
  
                      }
  
                  }
              }
  </code></pre>
  
  <p>for the client side i've got receveingdata method that i call in my main
  why i can't receive at least twice my stringbuilder sent i'am getting an error
  atthe second turn saying unable to read data from the transport connection an existing connection was closed by the distant host</p>
  
  <pre><code>public static void RecevingData()
          {
              IPAddress ipServeur;
              IPEndPoint ipeServeur;
              TcpClient tc = null;
              NetworkStream ns = null;
  
              try
              {
  
                  ipServeur = IPAddress.Parse("127.0.0.1");
                  ipeServeur = new IPEndPoint(ipServeur, 8888);
                  tc = new TcpClient();
  
                  tc.Connect(ipeServeur);
                  ns = tc.GetStream();
  
  
  
                  string s = null;
                  string s1 = "ping";
                  string reponse = null;
                  StreamWriter write = new StreamWriter(ns);
                  StreamReader reader = new StreamReader(ns);
                  //Console.WriteLine("un string svp");
                  //s = Console.ReadLine();
                  write.Flush();
                  write.WriteLine(s1);
                  write.Flush();
                  do
                  {
                      reponse = reader.ReadLine();
                      Console.WriteLine(reponse);
                  } while (true);
  
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.Message);
                  Console.ReadKey();
              }
  
  
          }
  </code></pre>
  
  <p>i am a beginner so maybe my question is too stupid but i am just driven by getting better so please try to be indulgent,my idea was to send the stringbuilder the same way after each player's turn</p>