Communication with server

Started by
4 comments, last by Evil Steve 15 years, 9 months ago
I'm trying to connect to a web server and retrieve the html document from it by using the sample from Ultimate Game Programming: http://www.ultimategameprogramming.com/zips/Cpp_SimpleTextBrowser.ZIP But when I try to run it, it's not working. I receive -1 when trying to receive the data. Could someone tell me what's wrong? I'm using Microsoft Visual C++ 2003 when compiling it.
Advertisement
put a break point in the start of the code and step through it, see if you can follow what is happening, it will probably show you where the fault lies.\
I did that, and I saw that the received bytes is -1. Which means that the receive method didn't work. The connection seems to work, but I don't receive any data.

The application is sending "GET / HTTP/1.0\n\n" to the web server, and then receives data from the server. But it looks like the server don't send anything back. Is the command "GET / HTTP/1.0\n\n" still correct way to receive HTML data?

i would check by telnetting to a webserver but vista does not come with it by default, so i can not confirm atm.
I found out the problem. He was using the wrong socket when receiving data. It works if I change the socket to the server socket. :)
Quote:Original post by RandomPixel
Is the command "GET / HTTP/1.0\n\n" still correct way to receive HTML data?
No. You need \r\n, not \n. And most servers will need a Host: parameter. I always send:
GET / HTTP/1.0\r\nHost: www.gamedev.net\r\n\r\n

This topic is closed to new replies.

Advertisement