title: Socket Programming in C# Is this considered polling?
body: <p>so I have been trying out socket programming in C# using code found online. When looking at this code from <a href="https://www.geeksforgeeks.org/socket-programming-in-c-sharp/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/socket-programming-in-c-sharp/</a></p>
  
  <pre><code>public static void ExecuteServer() 
  { 
      // Establish the local endpoint  
      // for the socket. Dns.GetHostName 
      // returns the name of the host  
      // running the application. 
      IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName()); 
      IPAddress ipAddr = ipHost.AddressList[0]; 
      IPEndPoint localEndPoint = new IPEndPoint(ipAddr, 11111);   
      // Creation TCP/IP Socket using  
      // Socket Class Costructor 
      Socket listener = new Socket(ipAddr.AddressFamily, 
                   SocketType.Stream, ProtocolType.Tcp);   
      try {           
          // Using Bind() method we associate a 
          // network address to the Server Socket 
          // All client that will connect to this  
          // Server Socket must know this network 
          // Address 
          listener.Bind(localEndPoint);   
          // Using Listen() method we create  
          // the Client list that will want 
          // to connect to Server 
          listener.Listen(10);   
          while (true) {               
              Console.WriteLine("Waiting connection ... ");   
              // Suspend while waiting for 
              // incoming connection Using  
              // Accept() method the server  
              // will accept connection of client 
              Socket clientSocket = listener.Accept();   
              // Data buffer 
              byte[] bytes = new Byte[1024]; 
              string data = null;   
              while (true) {   
                  int numByte = clientSocket.Receive(bytes);                   
                  data += Encoding.ASCII.GetString(bytes, 
                                             0, numByte);                                              
                  if (data.IndexOf("&lt;EOF&gt;") &gt; -1) 
                      break; 
              }   
              Console.WriteLine("Text received -&gt; {0} ", data); 
              byte[] message = Encoding.ASCII.GetBytes("Test Server");   
              // Send a message to Client  
              // using Send() method 
              clientSocket.Send(message);   
              // Close client Socket using the 
              // Close() method. After closing, 
              // we can use the closed Socket  
              // for a new Client Connection 
              clientSocket.Shutdown(SocketShutdown.Both); 
              clientSocket.Close(); 
          } 
      }       
      catch (Exception e) { 
          Console.WriteLine(e.ToString()); 
      } 
  } 
  } 
  } 
  </code></pre>
  
  <p>I was wondering if the portion </p>
  
  <pre><code>while (true) { 
                  int numByte = clientSocket.Receive(bytes); 
                  data += Encoding.ASCII.GetString(bytes, 0, numByte);                                   
                  if (data.IndexOf("&lt;EOF&gt;") &gt; -1) 
                      break; 
              } 
  </code></pre>
  
  <p>is considered a polling method and also reason why we do not simply use</p>
  
  <pre><code>int numByte = clientSocket.Receive(bytes);
  data = Encoding.ASCII.GetString(bytes, 0, numByte);
  </code></pre>
  
  <p>I have tried the above and it seems to work just as fine. So is there a reason why we use a infinite while loop that depends on the text  to stop reading? I have found many sources which seems to use this method. Why is this so?</p>