Ho trovato un esempio ma questo nel server mi dice che fallisce la bind().. vi prego aiutatemi..
// Initialize Winsock
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR)
printf("Error at WSAStartup()\n");
// Create a SOCKET for listening for incoming connection requests
SOCKET ListenSocket;
ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ListenSocket == INVALID_SOCKET) {
printf("Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return;
}
// The sockaddr_in structure specifies the address family, IP address,and port for the socket that //is being bound.
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr("127.0.0.1");
service.sin_port = htons(27015);
// Bind the socket.
if (bind( ListenSocket, (SOCKADDR*) &service, sizeof(service)) ==
SOCKET_ERROR) {
printf("bind() failed.\n");//mi stampa questo..
closesocket(ListenSocket);
return;
}
WSACleanup();