title: Creating sockaddr_in for CocoaAsyncSocket Getting Invalid IPv4 address
body: <p>I'm having trouble connecting to a Java socket server. I know the server is working because I connect via a Java socket. I'm using the CocoaAsyncSocket library to make a client connection from an iOS device. I've tried the following,</p>
  
  <pre><code>[socket connectToHost:@"XXX.XXX.X.XXX" onPort:9090 error:&amp;err]
  </code></pre>
  
  <p>method but the server never sees the client connect and the client (CocoaAsyncSocket) thinks its connected. So thats no good, then I realized there was another connection method available.</p>
  
  <p>So I'm thinking I should be using the connectToAddress method instead. <a href="https://stackoverflow.com/questions/9682142/how-to-create-ip-address-and-port-into-nsdata-to-work-with">I've used this post</a> as a reference for my current code but I'm still getting an error and I'm not sure why. The only difference from my version and the suggested version is for the length they use sa_len and I was getting a error and xCode wanted to switch it to sin_len, so I did. I'm really new to direct socket connections so bear with me.</p>
  
  <pre><code>GCDAsyncSocket *socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
  
  struct sockaddr_in ip4addr;
  
  ip4addr.sin_family = AF_INET;
  ip4addr.sin_port = htons(9090);
  inet_pton(AF_INET, "XXX.XXX.X.XXX", &amp;ip4addr.sin_addr);
  
  NSData *discoveryHost = [NSData dataWithBytes:&amp;ip4addr length:ip4addr.sin_len];
  
  NSError *err = nil;
  if (![socket connectToAddress:discoveryHost error:&amp;err])
  {
      NSLog(@"I CANNOT CONNECT!");
  }
  else
  {
      NSLog(@"IM CONNECTED!");
  }
  </code></pre>
  
  <p>The connection fails and the error is,</p>
  
  <pre><code>Error Domain=GCDAsyncSocketErrorDomain Code=2 "A valid IPv4 or IPv6 address was not given" UserInfo=0x8bac880 {NSLocalizedDescription=A valid IPv4 or IPv6 address was not given}
  </code></pre>