Wednesday, 11 September 2013

How to properly catch initial response of a server?

How to properly catch initial response of a server?

My c++ program is trying to check status of a ftp-server. It uses winsock
and simple testing function that looks like this (pseudocode):
create a tcp socket
connect to port 21 of the server
do recv() while data is available
close socket
return received data
It doesn't send any data to the server with send() - just trying to catch
server's initial response. And this actually works and returns "200
Response Server Ready" - this is exactly what I need. But after 2nd run of
the same function (immediatelly after 1st run) it returns nothing (because
recv() returns -1). Wireshark tells me that server really didn't send
response. After that I placed half-second pause between testing function
calls and now it works, but this solution is unwanted. The question is:
How to properly catch server's (not only ftp, but any other too) initial
response?
P.S. Sorry for my bad english

No comments:

Post a Comment