title: Reading TCP data freezes Unity
body: <p>I'm wanting my unity application to act like a server and read in some TCP strings that are being sent to it. However, the code I have at the moment seems to freeze my program and I have to go into the task manager to quit out.</p>
  
  <p>Can someone with more knowledge of TCP connections take a look over my code to see what I'm doing wrong and what the cause of this is?</p>
  
  <p>My entire class is as follows:</p>
  
  <pre><code>public class TCP : MonoBehaviour 
  {   
      string ip_address  = "127.0.0.1";
      int port = 22;
  
      // Use this for initialization
      void Start () 
      {
          Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
          var ipAddress = IPAddress.Parse(ip_address);
          EndPoint ep = new IPEndPoint(ipAddress, port);
          socket.Connect(ep);
  
          while(socket.Connected)
          {
              byte[] bytes = new byte[256];
              int i = socket.Receive(bytes);
              Debug.Log(Encoding.UTF8.GetString(bytes));
          }
      }
  
      // Update is called once per frame
      void Update () {
  
      }
  }
  </code></pre>
  
  <p>I have one request, my knowledge of this subject is very limited, if you make a suggestion to how I can fix it could you please either put up a code example so I can see how to implement it or link to something I can read to get more information?</p>