Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For whatever reason, I was not able to get a non blocking solution using "select" working. (But thank you both for your helpful responses.) I ended up using one of the socket options that let me specify a shorter timeout.</p> <pre><code>setsockopt(clientsock_fd, IPPROTO_TCP, TCP_CONNECTIONTIMEOUT, &amp;timeout, sizeof(timeout)); </code></pre> <p>In the interest of completeness, this is what I ended up with (error checking removed for clarity):</p> <pre><code>-(void)connect_to_control:(NSTimer*) timer </code></pre> <p>{</p> <pre><code>clientsock_fd = socket(AF_INET, SOCK_STREAM, 0); int no_delay = 1; int result = setsockopt(clientsock_fd, IPPROTO_TCP, TCP_NODELAY, &amp;no_delay, 4); // *** Set timeout value to stop hanging *** struct timeval timeout; timeout.tv_sec =1; timeout.tv_usec =0; result = setsockopt(clientsock_fd, IPPROTO_TCP, TCP_CONNECTIONTIMEOUT, &amp;timeout, sizeof(timeout)); struct sockaddr_in the_addr; memset((void *)&amp;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*)&amp;the_addr, sizeof(the_addr)); // hangs here when address can't be reached! </code></pre> <p><strong>NOTE:</strong> I had to upgrade to OS 3.0 to use <code>TCP_CONNECTIONTIMEOUT</code>. TCP_CONNECTIONTIMEOUT is defined in "tcp.h" the OS 3.0 SDK headers but not in OS 2.1. It is not defined in the simulator headers, only the device headers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload