Im trying to create a program using Windows sockets and i am getting an error code 0 when trying to create the socket
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.
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
.
Change to:
if (csocket == INVALID_SOCKET){
wprintf(L"socket function failed with error: %ld\n", WSAGetLastError());
}
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.