// JP opened flex table

Click to See Complete Forum and Search --> : beginner's question.


evonmj
June 6th, 2008, 05:19 PM
Hello, I am writing a simple Socket program using visual studio 2005, under windows xp, I create a console project, and the following is the piece of code.

#include <Winsock2.h>

int main()
{

SOCKET s = socket(PF_INET, SOCK_STREAM, 0);

}

I add Ws2_32.lib already, but it always return -1 as output, what is wrong with the code, any help will be appreciated.
Jimmy

ahoodin
June 6th, 2008, 05:30 PM
#include <Winsock2.h>

int main()
{
WSADATA wsaData;

if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) /* Load Winsock 2.0 DLL */
{
fprintf(stderr, "WSAStartup() failed");
exit(1);
}

SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
closesocket(s);
WSACleanup();
}

ahoodin
June 6th, 2008, 05:33 PM
sorry copy paste screwup. :D

load first then call socket.

//JP added flex table