C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-20-2001, 08:51 PM   #1
Unregistered
Guest
 
Posts: n/a
Simple Server problems...

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.
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 04:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22