title: Not able to send data via UDP
body: <p>I am not able to send UDP data to a system using IP address from my code.</p>
  
  <p>We make a connection through the constructor and than send the messages in the code below.</p>
  
  <p>This is my header File.</p>
  
  <pre><code>class UDPConnect
   {
    private:
     bool connected;
     SOCKET s;
     struct sockaddr_in server, si_other;
     int slen, recv_len;
  
     public:
          UDPConnect(const int iPort );   
          UDPConnect(const int iPort , const char* strHostName);
          int ReadIncomingPacket(byte *buffer, unsigned int buf_size);    
          int SendPacket(byte* buffer, unsigned int buf_size , const char* 
          strHostName);
          ~UDPConnect();
      };
  </code></pre>
  
  <p>This is the function defination.</p>
  
  <pre><code> UDPConnect::UDPConnect(const int iPORT , const char* strHostName)
    {
      this-&gt;connected = false;
      this-&gt;s;
      WSADATA wsa;
  
      //Initialise winsock
     std::cout &lt;&lt; ("\nInitialising Winsock...") &lt;&lt; std::endl;
     if (WSAStartup(MAKEWORD(2, 2), &amp;wsa) != 0)
      {
       std::cout &lt;&lt; ("Failed. Error Code : %d", WSAGetLastError()) &lt;&lt; 
       std::endl;
      exit(EXIT_FAILURE);
      }
  
    //Create a socket
    if ((this-&gt;s = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
    {
       std::cout &lt;&lt; ("Could not create socket : %d", WSAGetLastError());
    }
  
   std::cout &lt;&lt; ("Socket created.\n");
  
  //Prepare the sockaddr_in structure
  this-&gt;server.sin_family = AF_INET;
  this-&gt;server.sin_addr.s_addr = inet_addr( strHostName );
  this-&gt;server.sin_port = htons(iPORT);
  
  
  //Bind
  //if (::bind(this-&gt;s, (struct sockaddr *)&amp;this-&gt;server, sizeof(this-&gt;server)) 
   == SOCKET_ERROR)
  if (::bind(this-&gt;s, (struct sockaddr *)&amp;this-&gt;server, 0) == SOCKET_ERROR)
  {
      printf("Bind failed with error code : %d", WSAGetLastError());
      //exit(EXIT_FAILURE);
  }
  puts("Bind done");
  
  this-&gt;connected = true;
  
  }
  </code></pre>
  
  <p>///////////////////////////////////////////////////////////////////////////</p>
  
  <pre><code>int UDPConnect::SendPacket(byte *buffer, unsigned int buf_size , const char* 
   strHostName)
   {
  
     this-&gt;server.sin_addr.s_addr = inet_addr( strHostName );
    if ((this-&gt;recv_len = sendto(this-&gt;s, (char*)buffer, buf_size + 1, 0, 
    (struct sockaddr *) &amp;this-&gt;si_other, slen)) == SOCKET_ERROR)
     {
       std::cout &lt;&lt; ("No Outgoing packet : %d", WSAGetLastError());
       //return -1;
     }
  
  return recv_len;
  </code></pre>
  
  <p>}</p>