简体   繁体   English

Windows Socket 编程 - 错误代码 0

[英]Windows Socket Programming - Error Code 0

Im trying to create a program using Windows sockets and i am getting an error code 0 when trying to create the socket我正在尝试使用 Windows 套接字创建程序,但在尝试创建套接字时收到错误代码 0

int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != NO_ERROR) {
    wprintf(L"WSAStartup function failed with error: %d\n", iResult);
}

csocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 

if(csocket != INVALID_SOCKET){
    wprintf(L"socket function failed with error: %ld\n", WSAGetLastError());
}

The part that is failing is creating the socket and the output i am getting is "socket function failed with error: 0.失败的部分是创建套接字,我得到的输出是“套接字函数失败,错误:0。

Thanks for the help in advance.我在这里先向您的帮助表示感谢。

The if condition is wrong and the socket descriptor is actually being created as it does not equal INVALID_SOCKET . if条件错误,实际上正在创建套接字描述符,因为它不等于INVALID_SOCKET

Change to:改成:

if (csocket == INVALID_SOCKET){
    wprintf(L"socket function failed with error: %ld\n", WSAGetLastError());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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