开发者

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

开发者 https://www.devze.com 2023-04-11 09:55 出处:网络
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...

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消