title: Getting "Transport endpoint is not connected" in UDP socket programming in C++
body: <p>I am getting <code>Transport endpoint is not connected</code> error in UDP server program, while I am try to
  shutdown the socket via <code>shutdown(m_ReceiveSocketId, SHUT_RDWR);</code>
  Following is my code snippet:</p>
  
  <pre><code> bool UDPSocket::receiveMessage()
      {
          struct sockaddr_in serverAddr; //Information about the server
          struct hostent *hostp; // Information about this device 
  
          char buffer[BUFFERSIZE]; // Buffer to store incoming message
          int serverlen; // to store server address length
  
          //Open a datagram Socket
          if((m_ReceiveSocketId = socket(AF_INET, SOCK_DGRAM, 0)) &lt; 0)
          {
              Utility_SingleTon::printLog(LOG_ERROR,"(%s %s %d) UDP Client - socket() error",__FILE__,__func__, __LINE__);
              pthread_exit(NULL);
              return false;
          }
  
  
          //Configure Server Address.
          //set family and port
          serverAddr.sin_family = AF_INET;
          serverAddr.sin_port = htons(m_ListeningPort);
  
          if (bind(m_ReceiveSocketId, (struct sockaddr *) &amp;serverAddr,sizeof(struct sockaddr_in)) &lt; 0 )
          {
              Utility_SingleTon::printLog(LOG_ERROR,"(%s %s %d) UDP Client- Socket Bind error=%s",__FILE__,__func__, __LINE__,strerror(errno));
              pthread_exit(NULL);
              return false;
          }
  
          //TODO Re-Route Mechanism.
          if((serverAddr.sin_addr.s_addr = inet_addr(m_ServerIPStr.c_str())) == (unsigned long)INADDR_NONE)
          {
              /* Use the gethostbyname() function to retrieve */
              /* the address of the host server if the system */
              /* passed the host name of the server as a parameter. */
              /************************************************/
              /* get server address */
              hostp = gethostbyname(m_ServerIPStr.c_str());
              if(hostp == (struct hostent *)NULL)
              {
                  /* h_errno is usually defined */
                  /* in netdb.h */
                  Utility_SingleTon::printLog(LOG_ERROR,"%s %d %s %s %d", "Host Not found",  h_errno,__FILE__,__func__, __LINE__);
                  pthread_exit(NULL);
                  return false;
              }
              memcpy(&amp;serverAddr.sin_addr, hostp-&gt;h_addr, sizeof(serverAddr.sin_addr));
          }
  
  
          serverlen = (int )sizeof(serverAddr);
  
          // Loop and listen for incoming message 
          while(m_RecevieFlag)
          {
              int receivedByte = 0;
              memset(buffer, 0, BUFFERSIZE);
              //receive data from the server
              receivedByte = recvfrom(m_ReceiveSocketId, buffer, BUFFERSIZE, 0, (struct sockaddr *)&amp;serverAddr, (socklen_t*)&amp;serverlen);
              if(receivedByte == -1)
              {
  
                  Utility_SingleTon::printLog(LOG_ERROR,"[%s:%d#%s] UDP Client - receive error",__FILE__,__LINE__,__func__);
                  close(m_ReceiveSocketId);
                  pthread_exit(NULL);
                  return false;
              }
              else if(receivedByte &gt; 0)
              {
                  string rMesg;
                  rMesg.erase();
                  for(int loop = 0; loop &lt; receivedByte; loop++)
                      rMesg.append(1, buffer[loop]);
                  Utility_SingleTon::printLog(LOG_DEBUG,"[%s:%d#%s] received message=%d",__FILE__,__LINE__,__func__, rMesg.length());
                  QOMManager_SingleTon::getInstance()-&gt;setReceivedMessage(rMesg);
                  raise(SIGUSR1);
              }
  
          }
  
          close(m_ReceiveSocketId);
          pthread_exit(NULL);
          return true;
  
      }
  </code></pre>
  
  <p>Any help would be appreciated. 
  Thanks Yuvi.</p>