title: Httpwebrequest(client writemode) to TCPclient(Server Readmode) Approach
body: <p>I am working on sending data across the network with the traditional server-client model.</p>
  <p>Here Server starts the Tcplistener in a particular address and port. In this case, it is the local host.</p>
  <p>The client makes use of  WebRequest class in .net and takes the request stream and starts writing data into the request stream.</p>
  <p>Let me walk through the Server code class:</p>
  <pre><code>TcpListener tcpListener = new TcpListener(IPAddress.Parse(&quot;127.0.0.1&quot;),9309);
  tcpListener.Start()//Start the listener and wait for client to connect.
  while(true)
  {
   TcpClient newclient = tcpListener.AcceptTcpClient();
   if(newclient.Connected())
       {
       break;
       }
  }
  while(true)
  {
   
  ReadData(newclient);
  }
  public void ReadData(TcpClient newclient)
  {
              byte[] buffer = newbyte[50];
              Stream ns = newclient.GetStream();     
              ns.Read(buffer, 0, buffer.Length);
              Console.WriteLine( Encoding.UTF8.GetString(buffer));
   }
  </code></pre>
  <p>//End of Server class.</p>
  <p>Now let's see the Client Code class:-</p>
  <pre><code>         WebRequest Request = HttpWebRequest.Create(http://127.0.0.1:9309/DataChannel);
           Request.Method = &quot;POST&quot;;  
           //Below method registers to Server's AcceptTcpClient  and tcpclient is assigned.     
           Stream NetworkStream = ModifyCollimationRequest.GetRequestStream();
        int DataWritten = 0;
          while(true)
            {
              string Dname = &quot;\r\nPosting server with Data as {0}\r\n&quot;;
              byte[] dbytes = Encoding.UTF8.GetBytes(string.Format(Dname, ++DataWritten));
              ns.WriteAsync(dbytes, 0, dbytes.Length);
              ns.FlushAsync();
            }
  //End of Client code. Once the connection is established, the client keeps writing into the stream till the buffer size of &gt;65000 is reached without issue but the problem is with the Server.
  </code></pre>
  <p>In Server,
  Stream ns = newclient.GetStream();  -&gt; This line under ReadData() method of the server executes,
  but the the next line the code where Read() is used -&gt; the code does not throw exception nor reaches next line. It just exits while debugging or times out. Someone it feels like, I am not able to fetch the stream or stream is empty. But the client keeps writing without any issue.
  Can sometimes try this out and help me with what I am missing. Ultimately, I should be able to read the data available in a stream in any case but not sure why. Please add in your suggestions?</p>