Hey,
Firstly:
I'm trying to make a socket proxy server.
It will end up something like browser -> c++ -> PHP on a web server -> c++ -> browser.
So far I've got a program receiving the header requests from the browser. So step 1. The PHP bit is fine, I'm reasonably experienced there.
My question is:
Is there a specific order I need to do things in, and how can I go about sending the data from the PHP back to the browser?
I'm actually trying to send an html file (with faked headers) to the browser atm but with no success.
Function that gets the file:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
char* getFile() {
ifstream myReadFile;
myReadFile.open("text.txt");
char output[100];
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
}
}
myReadFile.close();
return output;
}
|
Winsock command to send it to the browser:
|
send( ClientSocket, getFile(), 5000, 0 );
|
I don't know how to get the file size in bytes so I guessed with 5000.
This is the file I'm trying to send to the browser as the fake html page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
HTTP/1.1 200 OK
Date: Tue, 13 Sep 2011 19:37:24 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
Content-Length: 4307
Connection: close
Content-Type: text/html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>thetree</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
hello
</body>
</html>
|
Am I doing this completely wrong?
If anyone can answer this I'd be extremely grateful.
Thanks
tree