Ich möchte verbinden zu einem bestimmten Server mit diesem Client-Code mit Winsock. Aber die erstellte Buchse ist ungültig, so dass ich "INVALID SOCKET".Winsock-Client-Socket ist ungültig
//Creating a socket for connecting to server
SOCKET hSocket;
hSocket = socket(AF_INET, SOCK_STREAM,0);
if (hSocket == INVALID_SOCKET) //this is true!
{
cout << "INVALID SOCKET" << endl;
}
/* This code assumes a socket has been created and its handle
is stored in a variable called hSocket */
sockaddr_in sockAddr;
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(54123);
sockAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
// Connect to the server
if (connect(hSocket, (sockaddr*)(&sockAddr), sizeof(sockAddr)) != 0)
{
cout << "ERROR while connecting" << endl;
}