before making a call to socket() you must call WSAStartup, here's a piece of code from a class i made that estamblishes a connection:
Code:
bool make_connection()
{
WSADATA wsaData;
struct hostent *h;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
error_log = "WSAStartup()\n";
return false;
}
if ((h = gethostbyname(host.c_str())) == 0)
{
error_log = "gethostbyname()\n";
return false;
}
memset(&address, 0, sizeof address);
address.sin_family = AF_INET;
address.sin_port = htons(port);
memcpy(&address.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
error_log = "socket()\n";
return false;
}
if (connect(sock, (struct sockaddr *)&address, sizeof address) == -1)
{
closesocket(sock);
error_log = "connect";
return false;
}
is_connected = true;
return true;
}