title: TCP Client Server Problem
body: <p>I have the following code for the server application:</p>
  
  <pre><code>        TcpListener recSock = new TcpListener(400);
          recSock.Start();
          TcpClient client = recSock.AcceptTcpClient();
          NetworkStream netStream = client.GetStream();
  
          Byte[] data = new Byte[256];
  
          int i;
  
          while((i = netStream.Read(data, 0, data.Length)) != 0) {
              string cmd = ASCIIEncoding.ASCII.GetString(data, 0, i);
              Console.WriteLine(cmd);
              if(cmd == "R") {
                  RestartScheduler();
              }
          }
  
          client.Close();
  </code></pre>
  
  <p>And the client looks like:</p>
  
  <pre><code>        TcpClient client = new TcpClient();
          client.Connect("VM-SCHEDULER", 400);
          NetworkStream netStream = client.GetStream();
          Byte[] data = ASCIIEncoding.ASCII.GetBytes("R");
          netStream.Write(data, 0, data.Length);
          netStream.Flush();
          client.Close();
  </code></pre>
  
  <p>All is fine the first time the client connects the "R" command is read and the RestartScheduler() method is called, however all subsequent commands fail until the server is restarted.</p>
  
  <p>I have used telnet to connect to the server after the first attempt and it is still listening on the port.</p>
  
  <p>Where am i going wrong?</p>
  
  <p>EDIT:</p>
  
  <p>Basically what I am trying to accomplish is that the server will listen always, a client will then connect send the  "R" command then close the connection. The client must be able to connect to the server at any time to issue the command. There will only be 1 client at any given time.</p>