title: Connect to Acquisition unit(WIFI device) from iPhone/iPad programmatically
body: <p>I have a hardware device Acquisition unit. This device itself act as wifi router and it will send data. I want to connect it from iPhone/iPad.</p>
  
  <p>I heard that using IP address and port number we can connect to the wifi router using socket programming. But I don't have any idea about this socket program to connect to the wifi using IP address and port number.</p>
  
  <p>For this I have tried to get the IP address of a connected wifi router using following code.</p>
  
  <pre><code>NSString *address = @"error";
  struct ifaddrs *interfaces = NULL;
  struct ifaddrs *temp_addr = NULL;
  int success = 0;
  // retrieve the current interfaces - returns 0 on success
  success = getifaddrs(&amp;interfaces);
  if (success == 0) {
      // Loop through linked list of interfaces
      temp_addr = interfaces;
      while(temp_addr != NULL) {
          if(temp_addr-&gt;ifa_addr-&gt;sa_family == AF_INET) {
              // Check if interface is en0 which is the wifi connection on the iPhone
              if([[NSString stringWithUTF8String:temp_addr-&gt;ifa_name] isEqualToString:@"en0"]) {
                  // Get NSString from C String
                  address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr-&gt;ifa_addr)-&gt;sin_addr)];
  
              }
  
          }
  
          temp_addr = temp_addr-&gt;ifa_next;
      }
  }
  // Free memory
  freeifaddrs(interfaces);
  return address;
  </code></pre>
  
  <p>If it is possible to connect to the wifi router using ip address and port number could you please help me with some code or idea.</p>
  
  <p>Please help me..</p>
  
  <p>Thanks</p>