title: Close Client Socket on disconnect
body: <p>I have server application that listens for clients.
  Let's client lost internet connection and lost connection with server.</p>
  
  <p>Does server automatically check when a client was disconnected? If not how may I implement such thing?</p>
  
  <p>Main.cs <a href="http://pastebin.com/fHYpErz7" rel="nofollow">http://pastebin.com/fHYpErz7</a></p>
  
  <p>ServerSocket.cs: <a href="http://pastebin.com/erw4tzdp" rel="nofollow">http://pastebin.com/erw4tzdp</a></p>
  
  <p>Client.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Net.Sockets;
  
  namespace jM2
  {
      class Client
      {
          private int clientConnectionID;
          private Socket clientSocket;
          private string clientIP;
          private byte[] clientBuffer = new byte[1024];
  
          public Client(int connectionID, Socket connectionSocket)
          {
              clientConnectionID = connectionID;
              clientSocket = connectionSocket;
              clientIP = connectionSocket.RemoteEndPoint.ToString();
              clientSocket.BeginReceive(clientBuffer, 0, clientBuffer.Length, SocketFlags.None, new AsyncCallback(dataArrival), null);
          }
          public void Disconnect()
          {
              clientSocket.Close();
          }
          private void dataArrival(IAsyncResult iar)
          {
              int bytesReceived = clientSocket.EndReceive(iar);
              clientSocket.BeginReceive(clientBuffer, 0, clientBuffer.Length, SocketFlags.None, new AsyncCallback(dataArrival), null);
          }
      }
  }
  </code></pre>