title: Can't Connect to Twitch IRC Server, problem with IP address, C language
body: <p>I'm trying to build a ChatBot for Twitch entirely in C Language. But i'm having problems in connecting to the server: <code>irc.chat.twitch.tv</code> with port <code>6667</code>. I'm calling <code>gethostbyname()</code> to retrieve the ip address of the hostname, but the connect function never establish the connection, and returns "Connection Failed". </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;netdb.h&gt;
  
  #include "Authentication.h"
  #include "MessageHandlers.h"
  
  
  int main()
  {
      int sock;
      struct sockaddr_in addr;
      struct hostent * addr_info;
      char * ip;
      addr_info = gethostbyname("irc.chat.twitch.tv");
  
      ip = inet_ntoa(*(struct in_addr *)addr_info-&gt;h_name);
      printf("%s", ip);
      addr.sin_family = AF_INET;
      addr.sin_port = htons(6667);
      addr.sin_addr.s_addr = inet_addr(ip);
  
      sock = socket(AF_INET, SOCK_STREAM, 0);
      if(sock &lt; 0)
      {
          fprintf(stderr, "\nSocket Creation Failed\n");
          exit(EXIT_FAILURE);
      }
      printf("\nConnecting to Twitch IRC Server...\n");
      if(connect(sock, (struct sockaddr *)&amp;addr, sizeof(addr)) == -1)
      {
          fprintf(stderr, "\nConnection Failed\n");
          exit(EXIT_FAILURE);
      }
  
     // SendAuthentication(sock);
  /*
      while(1)
      {
       OnMessageEvents(sock);
      }
    */  
  
     exit(EXIT_SUCCESS);
  }
  </code></pre>
  
  <p>Is there something i'm doing wrong? The twitch resolved ip address seems to be <code>105.114.99.45</code>. I searched on Google for the actual ip address, but i didn't find any answers.</p>
  
  <p>I used <code>nslookup irc.chat.twitch.tv</code> and tried all the ip addresses, but still i got "Connection Failed".</p>
  
  <p>If i use <code>telnet irc.chat.twitch.tv 6667</code> i get a connection and i can perform the login.</p>