Did the server receive my send?

If this is in the wrong forum I apologize. I'm working with winsock to send a request to a server via the send command. I'm then supposed to receive the response (via recv.) My problem is that I don't seem to get anything back, which is somewhat frustrating.

What I want to know is if there is anyway to check if the server received my request? My company doesn't own the server and I only work during the weekend (teacher during the week) so nobody is at the company to call up and ask them.
If you get a reply, you know the server received your message. If not, that means it didn't receive anything or that it decided not to reply (for example, because the message was malformed).
If you're using TCP, the other side will always send an acknowledgement, even if it doesn't send back any data. If you don't receive the ACK, you'll notice because the connection will be aborted after a while and all further send and receive attempts on that socket will fail.

Talking about failing, are you checking the return values of all socket functions you call?
closed account (ozUkoG1T)
May i see the source code Because i am quite familiar with these sort of things i did make one of a command based Bot.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
int main(int argc, char *argv[])
{
    string request;
    string response = "";
    int resp_leng;
	
    char buffer[BUFFERSIZE];
    struct sockaddr_in serveraddr;
    int sock;

    WSADATA wsaData;
    char *ipaddress = "173.203.216.184";
    int port = 80;
	

	//This sets up the request function as Mace required. The 'Authorization' is our user name and password converted to Basic64
    request="GET /Date of the Data I need\r\n";
    request+="Host: Server ID\r\n";
    request+="Authorization: Basic My Password (not telling)\r\n";

    //init winsock
    WSAStartup(MAKEWORD(1, 0), &wsaData);;
    //open socket
    sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    //connect
    memset(&serveraddr, 0, sizeof(serveraddr));
    serveraddr.sin_family      = AF_INET;
    serveraddr.sin_addr.s_addr = inet_addr(ipaddress);
    serveraddr.sin_port        = htons((unsigned short) port);
    connect(sock, (struct sockaddr *) &serveraddr, sizeof(serveraddr));
    //send request
	send(sock, request.c_str(), request.length(), 0);


    //get response
    resp_leng = BUFFERSIZE;
	
	//MAKE THIS LINE WORK!
	//setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char*)&n,sizeof(int));



    while (resp_leng == BUFFERSIZE)
    {
		resp_leng = recv(sock, (char*)&buffer, BUFFERSIZE, 0); //Here is the error, unless the mace server isn't recieving the request
		if (resp_leng>0)
            response += string(buffer).substr(0,resp_leng);
        //note: download lag is not handled in this code
    }
	system("pause");
    //display response
    cout << response << endl;
	printf("/nResponse Is:%s", response);
	system("pause");
    //disconnect
    closesocket(sock);
	//cleanup
    WSACleanup();
    return 0;
}

Obviously this in an amateur hour program (and in the middle of being worked on if you notice obvious qwerks) but I do not know why I'm not receiving anything in response. Any help would be greatly appreciated.

Thanks to those who've already replied.
You need to check the return values. You can't just proceed with send() after connect() when you don't even know if the connect was successful. When something doesn't work, that's the first thing you should check if you weren't already doing it.

A HTTP get request must be terminated with an empty line (so an extra \r\n) which is missing in yours. Until the server receives that empty line, it is not going to do anything.

The following isn't going to work:
response += string(buffer).substr(0,resp_leng);
buffer will be treated as a null-terminated string, which it is not. It should be:
response += string(buffer,buffer+resp_leng);

Your current loop will stop after the first call to recv(), however you need to loop until the other side closes the connection or until you know there is no data left to receive.
You should implement an error-checking system as well as a way to properly handle any possible errors.
As your code is now, there's little way to know if your code runs successfully (never assume it's perfect).

Also, you may need to forward your port if you want your server visible to the "outside".
If this is a serious project, I advice you to use a full featured http client, like CURL. As for knowing if the server is running, just open the URL in your web browser.
Athar- Thanks. I'll be trying that out today. Appreciate the input.

Nexius- I did actually have some error checking in their but took it out to test if that was the issue (it was unlikely but I'm pulling my hair out here.) I'll be putting it back soon. I have backups of the previous versions of the program to pull it from.

modoran- Wow, I don't know why I didn't think of that. Tried it today and at least I now know that the server is running, even it I can't do anything with it via a web browser.
I've got that program working but it times out telling me that I haven't sent a complete request.

Below is the response I get:

Press any key to continue . . .
HTTP/1.0 408 Request Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>408 Request Time-out</h1>
Your browser didn't send a complete request in time.
</body></html>

Press any key to continue . . .
Sounds like you're still not sending the newline. Your code?
That was it. Added it when you gave me the initial advice but somehow I took it out between now and then. Thanks.
Well, it working and I'm almost positive my problem isn't C++ related but you guys have been so helpful that I figured I'd ask here anyway.

It's giving me an HTTP Error 303

1
2
3
4
5
6
7
8
9
10
11
12
Press any key to continue . . .
HTTP/1.0 303 See Other
Location: http://guidetest.a.id.opendns.com/?url=data%2Emacemeters%2Ecom%2Fdownl
oad%3Fstart%2Ddate%3D2012%2D10%2D24T09%3A30%26end%2Ddate%3D2012%2D10%2D24T10%3A0
0
Content-Length: 0
Connection: close
Date: Sun, 18 Nov 2012 17:32:58 GMT
Server: OpenDNS Guide


Press any key to continue . . .

From my research it is trying to tell me that I need to go to the new location for the data I want but that keeps redirecting me to another, then another, then another location, ad infinitum. The program is basically the same as I posted above with a different IP address, fixed response, and fixed request (per athar's helpful advice.)

Is this my problem or is this something I need to contact the company who's server I'm trying to access about?
Topic archived. No new replies allowed.