title: Detect disconnect Winsock C++
body: <p>I am new to c++. I understand Object Oriented Programming.</p>
  
  <p>I followed a tutorial and put together this Client/Server code. I would now like to add a message to the server when a client is disconnected.</p>
  
  <p>im using vs11</p>
  
  <p>Server:</p>
  
  <pre><code>#include "main.h"
  
  using namespace std;
  
  void main ( )
  {
      long answer;
      WSAData wsaData;
      WORD DLLVERSION;
      DLLVERSION = MAKEWORD(2,1);
  
      answer = WSAStartup(DLLVERSION, &amp;wsaData);
  
      //WINSOCK LOADED
  
      SOCKADDR_IN addr;
      int addrlen = sizeof(addr);
  
      SOCKET sListen;
      SOCKET sConnect;
      SOCKET* Connections;
      static int ConCounter = 0;
  
      Connections = (SOCKET*)calloc(64, sizeof(SOCKET));
  
      sConnect = socket(AF_INET,SOCK_STREAM,NULL);
  
      addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  
      addr.sin_family = AF_INET;
  
      addr.sin_port = htons(1234);
  
  
      sListen = socket(AF_INET,SOCK_STREAM,NULL);
  
      bind(sListen, (SOCKADDR*)&amp;addr, sizeof(addr));
  
      listen(sListen, SOMAXCONN);
  
      for(;;)
      {
          cout &lt;&lt; "Wating for connection..." &lt;&lt;endl;
  
          if(sConnect = accept(sListen, (SOCKADDR*)&amp;addr, &amp;addrlen))
          {
              Connections[ConCounter] = sConnect;
  
              cout &lt;&lt; "Connection found " &lt;&lt; ConCounter &lt;&lt;endl;
  
              answer = send(Connections[ConCounter], "YourMessage", 12, NULL);
  
              ConCounter++;
          }
      }
  }    
  </code></pre>
  
  <p>Client: </p>
  
  <pre><code>#include "main.h"
  
  using namespace std;
  
  void main ( )
  {
      string confirm;
      char message[200];
      string strmessage;
  
      long answer;
      WSAData wsaData;
      WORD DLLVersion;
      DLLVersion = MAKEWORD(2,1);
      answer = WSAStartup(DLLVersion, &amp;wsaData);
  
      SOCKADDR_IN addr;
  
      int addrlen = sizeof(addr);
  
      SOCKET sConnect;
  
      sConnect = socket(AF_INET, SOCK_STREAM,NULL);
  
  
  
      addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  
      addr.sin_family = AF_INET;
  
  
      addr.sin_port = htons(1234);
  
      cout &lt;&lt; "Do you want to connect to the Server? [Y/N]" &lt;&lt;endl;
      cin &gt;&gt; confirm;
  
      if(confirm == "N")
      {
          exit(1);
      }
      else
      {
          if(confirm == "Y")
          {
              connect(sConnect, (SOCKADDR*)&amp;addr, sizeof(addr));
  
              answer = recv(sConnect, message, sizeof(message), NULL);
  
              strmessage = message;
              cout &lt;&lt; strmessage &lt;&lt;endl;
  
              getchar();
          }
      }
      getchar();
  }
  </code></pre>