title: How to understand whether client connected to server in c#?
body: <p>I am trying to make connection between a client and a server using sockets. I have a GUI for this. Here is my code:</p>
  
  <p>This is the code for the server, it takes the port number from a textbox in the gui, and when start button is clicked, a socket is created.</p>
  
  <pre><code>Thread thrAccept;
  Socket server_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  Socket n;
  
  private void button_start_listening_Click(object sender, EventArgs e)
  {
      richTextBox_server_activity_log.AppendText("Server started. Waiting for clients... \n");
      button_start_listening.Enabled = false;
      server_socket.Bind(new IPEndPoint(IPAddress.Any, Convert.ToInt32(textbox_port_no.Text)));
  
      server_socket.Listen(100);
      thrAccept = new Thread(new ThreadStart(Accept));
      thrAccept.Start();
  
  }
  
  private void Accept()
  {
      n = server_socket.Accept();            
  }
  </code></pre>
  
  <p>And for the client, i have enter the ip and port numbers from the users using two textboxes and click the connect button, and to establish connection, i use this piece of code:</p>
  
  <pre><code>c.Connect(ipText.Text, Convert.ToInt32(portText.Text)); //c is a socket
  </code></pre>
  
  <p>My question is, when the connection is established, i want to print something like "Client connected" in the GUI of the server. But how can i let server know that client has connected?</p>
  
  <p>Thank you</p>