title: C# StreamSocket maximum timeout period server to client communication
body: <p>I have got the following piece of code from MSDN. Basically, I want to create an app (client) that constantly waits for a command from the server to do some task. Because the server cannot talk to the client directly, the client has to open the connection to the server, request something while the server keeps the request open indefinitely until it responds to the client with the command. reader.ReadLineAsync() will block execution until the server responds. Is there a maximum timeout period for reader.ReadLineAsync()? Or is there a better way to do this?</p>
  
  <pre><code>try
  {
      //Create the StreamSocket and establish a connection to the echo server.
      Windows.Networking.Sockets.StreamSocket socket = new Windows.Networking.Sockets.StreamSocket();
  
      //The server hostname that we will be establishing a connection to. We will be running the server and client locally,
      //so we will use localhost as the hostname.
      Windows.Networking.HostName serverHost = new Windows.Networking.HostName("localhost");
  
      //Every protocol typically has a standard port number. For example HTTP is typically 80, FTP is 20 and 21, etc.
      //For the echo server/client application we will use a random port 1337.
      string serverPort = "1337";
      await socket.ConnectAsync(serverHost, serverPort);
  
      //Write data to the echo server.
      Stream streamOut = socket.OutputStream.AsStreamForWrite();
      StreamWriter writer = new StreamWriter(streamOut);
      string request = "test";
      await writer.WriteLineAsync(request);
      await writer.FlushAsync();
  
      //Read data from the echo server.
      Stream streamIn = socket.InputStream.AsStreamForRead();
      StreamReader reader = new StreamReader(streamIn);
      string response = await reader.ReadLineAsync();
  }
  catch (Exception e)
  {
  //Handle exception here.            
  }
  </code></pre>