well just writing my first server here. here is some of what ive got:
void acceptproc(void *pParam) {
SOCKET theClient;
theClient = accept((SOCKET)pParam,
NULL, NULL);
if (theClient == INVALID_SOCKET) {
printf("Error at accept()");
closesocket(theClient);
_endthread();
}
_beginthread(acceptproc,0,pParam);
// start the thread for sending receiving...
printf("acceptproc ending.");
_endthread();
}
int main(int argc, char** argv) {
WORD version = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;
//Start Winsock
WSAStartup(version, &wsaData);
//Create the socket
SOCKET listeningSocket;
listeningSocket = socket(AF_INET, // Go over TCP/IP
SOCK_STREAM, // Socket type
IPPROTO_TCP); // Protocol
if (listeningSocket == INVALID_SOCKET) {
printf("Error at socket()");
return 0;
}
// Use SOCKADDR_IN to fill in address information
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr.s_addr = INADDR_ANY;
saServer.sin_port = htons(8888);
nRet = bind(listeningSocket, (LPSOCKADDR)&saServer, sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR) {
printf("Error at bind()");
return 0;
}
// Make the socket listen
nRet = listen(listeningSocket, 10);
if (nRet == SOCKET_ERROR) {
printf("Error at listen()");
return 0;
}
_beginthread(acceptproc,0,(void *)listeningSocket);
closesocket(listeningSocket);
// Shutdown Winsock
WSACleanup();
}
this piece along with the other bits that i dont have problems with compile, but when i run the program, then it fails at accept(). theClient come out as and INVALID_SOCKET.... alright. if you can tell me what is wrong.