简体   繁体   中英

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?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM