title: C# continuous socket listening
body: <p>I am trying to setup a server that continuously reads the strings that come throught a port.
  I have come up to some piece of code but it will only read one string and then stop.
  How can I modify it so that it continously reads the strings that come to that port and puts them into the textbox?</p>
  
  <p>I have tried putting a "while(true)" but that would hung up my form.I am currently researching on how to make the socket listening in a backgroundWorker or Thread.</p>
  
  <pre><code>public void start_server()
      {
              _server_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
              _server_socket.Bind(new IPEndPoint(IPAddress.Any, 1234));
              _server_socket.Listen(0);
              _server_socket.BeginAccept(new AsyncCallback(AcceptCallback), null);
      }
  
      private void AcceptCallback(IAsyncResult AR)
      {
              _client_socket = _server_socket.EndAccept(AR);
              _buffer = new byte[_client_socket.ReceiveBufferSize];
                  _client_socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null);
      }
  
      private void ReceiveCallback(IAsyncResult AR)
      {
              string text = Encoding.ASCII.GetString(_buffer);
              write(text);
      }
  
      private void write(string text)
      {
          MethodInvoker invoker = new MethodInvoker(delegate
              {
                  textBox1.Text =textBox1.Text+text;
              });
          this.Invoke(invoker);
      }
  </code></pre>