![]() |
| | #1 |
| Guest
Posts: n/a
| Simple Server problems... 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. |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems with a simple console game | DZeek | C++ Programming | 9 | 03-06-2005 02:02 PM |
| errm, problems with da server... | jverkoey | A Brief History of Cprogramming.com | 4 | 03-17-2003 04:19 PM |
| problems in with design of a server project. | codec | C++ Programming | 4 | 02-28-2003 09:11 AM |
| simple class, any problems? | Syneris | C++ Programming | 6 | 04-05-2002 12:18 PM |
| Socket Problems | (TNT) | Windows Programming | 4 | 08-18-2001 06:59 AM |