Winsock

closed account (o1vk4iN6)
Here's the code I have:
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
WSADATA wsaData;

    if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
		cout << "WSAStartup failed.\n";
        system("pause");
		return 1;
    }

	SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

	struct hostent *host;
	host = gethostbyname("google.com");

	SOCKADDR_IN SockAddr;
	SockAddr.sin_port=htons(80);
	SockAddr.sin_family=AF_INET;
	SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
	printf("IP Address: %s\n", inet_ntoa(*(in_addr*)host->h_addr));
	connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr));
	send(Socket,"GET \n\r\n\r", 8,0);
	char buffer[100000];
	
	int nDataLength = recv(Socket,buffer,100000,0);
	cout << buffer;

	closesocket(Socket);
    WSACleanup();


The problem is, essentially with the IP. It will work for google with the said code but when I try my website it doesn't work. I get the ip address and try changing the code to this:
1
2
char *ipaddress = "173.194.33.104";//Google.com
serveraddr.sin_addr.s_addr = inet_addr(ipaddress);

It returns website not found, for both methods using my website. The samething happens when I try to access my website using the ip address in an internet browser, but works fine with I enter the domain. I must be missing something, any thoughts on what I'm doing wrong?

I simple want to get a web page, which is just some simple php code that echoes 0 or 1 depending on the inputed information.
It will work for google ... when I try my website it doesn't work.

It returns website not found ... using my website. The samething happens when I try to access my website using the ip address in an internet browser, but works fine with I enter the domain.


You haven't said what exactly works, what doesn't work.
Sounds like a reverse DNS issue to me. If you're experiencing the same problems with your browser as well as your app - it's not your app that's the problem.

I suggest you contact your domain name provider and/or your host provider.
1. SockAddr struct might different.
2. If you pay attention, DNS names are always 2, when you register to domain names.

if I am wrong, please give me correct answer please, I wonna know!
Thnks!
Topic archived. No new replies allowed.