Re: Check if FTP server isn't offline, my prog allways saying it is online
to limit the time for the connect() request to succeed, you can
- set your socket to non-blocking
- call connect which will now immediately return with an error indicating the function would block
- call select with the desired timeout
- if select returns, either your connection succeeded or the timeout happened.
As to gethostbyname: it may fail if you pass a name (not IP address) to it which your operating system can not resolve.
Re: Check if FTP server isn't offline, my prog allways saying it is online
Quote:
- call connect which will now immediately return with an error indicating the function would block
what do you mean? i do call connect
Code:
if (connect(s,(struct sockaddr *)&server, sizeof(server))< 0) {
return NULL;
}
Re: Check if FTP server isn't offline, my prog allways saying it is online
all of those 4 items I mentioned do belong together in this order. Follow them from top to bottom and you will be able to restrict the connection attempt to match your timeout requirements.
But one addtional thing: if the attempt times out, make sure to close the socket or you might have an unwanted connection later.
Re: Check if FTP server isn't offline, my prog allways saying it is online
ok... i got timeout thing working with select, but when i wrote correct ip back and turned on my FTP nothing changed =\ i still get my timeout and no connection
Code:
timeval tvTimeout;
tvTimeout.tv_sec = 4; // <-- Maximum (?) timeout value
tvTimeout.tv_usec = 0;
fd_set fds; FD_ZERO(&fds);
FD_SET(s, &fds);
INT iStatus = SOCKET_ERROR;
iStatus = ::select(0, &fds, NULL, NULL, &tvTimeout);
if (SOCKET_ERROR == iStatus || 0 == iStatus) {
return NULL;
}
Re: Check if FTP server isn't offline, my prog allways saying it is online
last chance to post a complete sample code that demonstrates your problem ...