For what reasons would connect() fail?
Attached is the full source. Below is where connect fails.

SOCKET openSocket(const char *IP, int port){
   int ret;

   struct sockaddr_in my_addr;
   my_addr.sin_family = AF_INET;         // host byte order
   my_addr.sin_port = htons(port);       // short, network byte order
   if (inet_addr(IP) == (unsigned)-1)    // error checking
      return 0;
   my_addr.sin_addr.s_addr =
      inet_addr(IP);                     // set the address
   memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct

   SOCKET sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // do some error checking!
   if (sockfd == -1) error("Error in sockfd!","sockfd");
   ret = connect(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
   if (ret = -1) error("Error in connect!","connect");
   return sockfd;