1. timer_timeout() ==================== sock_fd = socket(AF_INET,SOCK_STREAM,0) /* Set the time out*/ t_timeout.tv_sec = 0; t_timeout.tv_nsec = 1000000; // 1 ms timer_timeout(CLOCK_REALTIME, _NTO_TIMEOUT_REPLY, NULL, &t_timeout, NULL); ret = connect(sock_fd, (struct sockaddr *)&address, sizeof(address)); 2. select() ============== sock_fd = socket(AF_INET,SOCK_STREAM,0) arg = fcntl(create_socket, F_GETFL, NULL); arg |= O_NONBLOCK; fcntl(sock_fd, F_SETFL, arg); ret = connect(sock_fd, (struct sockaddr *)&address, sizeof(address)); if (ret < 0) { if (errno == EINPROGRESS) { tv.tv_sec = 1; tv.tv_usec = 0; //1000 FD_ZERO(&myset); FD_SET(create_socket, &myset); if (select(create_socket+1, NULL, &myset, NULL, &tv) > 0) { lon = sizeof(int); getsockopt(create_socket, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon); if (valopt) { fprintf(stderr, " SO_ERROR in connection %d - %s\n", valopt, strerror(valopt)); exit(0); } } else { fprintf(stderr, "Select Timedout or error - %s\n", strerror(errno)); exit(0); } } }