simple HTTP response

I'm writing a server that will send a simple text file with some info.

I read the html 1.1 response section from specs here:
http://www.rfc-editor.org/rfc/rfc2616.txt

So I wait for connection, wait for request which I ignore and than send

char * sendb=
"HTTP/1.1 403 Forbidden\r\n\
\0"

I'm running the server atm, so if you want to check what happens just enter http://cpptemp.ath.cx in your browser window (temp dyndns)


This is the code:
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
inline void client_recv(SOCKET client){
	char buf[5120];
	int result = recv(client, buf, 5120, 0);
	if(result==SOCKET_ERROR){
		debug(L"Napaka! <%d>", WSAGetLastError());
		return;
	};
	debug(L"Prejel - Poglej debug screen!");
	buf[result]='\0';
	OutputDebugStringA(buf);


	char * sendb	= 
"HTTP/1.1 403 Forbidden\r\n\
\0";
	
	//sendb[0]		= MSG_HELLO;
	//*(short*)((sendb+1))	= reg&_clients;		

	result		= send(client, sendb, strlen(sendb)+1, 0);
	if(result==SOCKET_ERROR){
		debug(L"Napaka pri poĊĦiljanju MSG_HELLO <%d>", WSAGetLastError());
		//cleanup
		//Socket is unregistred here
		//container.pop_back();
		return;;
	};

	debug(L"Poslano %db", strlen(sendb)+1);
}
//...
LRESULT CALLBACK MainWproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
	//...
				case FD_READ:
					if(wParam==server_file){
						update_recv();
					}
					else{
						client_recv((SOCKET)wParam);
					}
					break;
	//...

};


There are no error messages generated by winsock, but I havent manualy checked what I send from my client jet.


I know it's kinda offtopic, but I hope I'll be forgiven :]
Last edited on
I couldn't see your output. But I'd guess you need a double \r\n to indicate end of request to the server.
As I understand it, the second CRLF is only when returning additional headers (general-header | response-header | entity-header). I tried it anyway, nothing. Slowly making my way thru the specifications now.

What I learnt from wireshark:
a Content-type header is required :D it works now.
Last edited on
Topic archived. No new replies allowed.