Sebastiani
Programmer
Hi, all. I am having a problem getting connect() to complete successfully. I've tried to isolate the problem a bit, and in the below example simply use the manifest constant INADDR_LOOPBACK for simplicity. Any help would be greatly appreciated!
Code:
#include <iostream>
#include <winsock.h>
int main()
{
WSADATA wsa;
if(WSAStartup(0x0101, &wsa)!=0)
cout << "!WSAStartup()" << endl;
else
{
SOCKET handle = socket(AF_INET, SOCK_STREAM, 0);
if(handle == INVALID_SOCKET)
cout << "!socket()" << endl;
else
{
sockaddr_in addr;
memset(&addr, 0, sizeof(sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
addr.sin_addr.s_addr = INADDR_LOOPBACK;
if(connect(handle, (sockaddr*)&addr, sizeof(sockaddr_in)) == SOCKET_ERROR)
cout << "!connect()" << endl;
else
{
cout << "Yahoo!" << endl;
}
shutdown(handle, SD_BOTH);
closesocket(handle);
}
WSACleanup();
}
return cin.get();
}