I've inherited a iPhone application/project that opens a socket connection to another device (think web cam). This works fine as long as the device is reachable over the wifi network. However, if it isn't reachable, the application hangs calling "connect".
(Error checking stripped out for clarity.)
-(void)connect_to_control:(NSTimer*) timer
{
clientsock_fd = socket(AF_INET, SOCK_STREAM, 0);
int no_delay = 1;
setsockopt(clientsock_fd, IPPROTO_TCP, TCP_NODELAY, &no_delay, 4);
struct sockaddr_in the_addr;
memset((void *)&the_addr, 0, sizeof(the_addr));
the_addr.sin_family = AF_INET;
the_addr.sin_port = htons(25556);
const char* server_addr = "192.168.3.22";
unsigned long ip_addr = inet_addr(server_addr);
the_addr.sin_addr.s_addr = ip_addr;
int err_test = connect(clientsock_fd, (const struct sockaddr*)&the_addr, sizeof(the_addr));
}
My first thought was to "ping" the address to see if it is reachable. So far I've discovered Apples "Reachability" sample but that does NOT determine if an address is reachable, only if the network is reachable (except in the simulator) and an old Apple sample "SimplePing" which uses header files that aren't included in the iPhone SDK.
I've got decades of C++/C# experience but I'm an iPhone noob trying to help out a friend's little company debug some stuff in time for an important trade show. Thanks in advance.