EBAG
EBAG

Reputation: 22601

Why socket(PF_INET,SOCK_STREAM,0) returns -1?

I trying to create a socket application on visual studio c++, but I can't.

The problem is int listen_sock = socket(PF_INET,SOCK_STREAM,0) returns -1 and I don't know why...

What am I doing wrong?

Upvotes: 0

Views: 831

Answers (2)

cnicutar
cnicutar

Reputation: 182734

You should print the error (using GetLastError). I suspect you are not initializing things:

WSADATA wsaData = {0};
WSAStartup(MAKEWORD(2, 2), &wsaData);

Upvotes: 2

Jon Bright
Jon Bright

Reputation: 13748

What does WSAGetLastError return? Did you call WSAStartup before doing this call?

Upvotes: 4

Related Questions