|I'm looking for multi-user server source code (tutorial) (C/C++, sockets, no MFC).
Oh, I already know how to do multi connections the windows way (messages sent to my window when data is received), but that's not what I want.
I know there are some here at codeproject but they all use MFC (yuck) and seem alot more complicated then what I've found so far.
I found the original at www.planet-source-code.com (I've re-done and simplified it for this post):
int RetVal = 0;
DWORD WINAPI acceptingThreadProcedure(LPVOID ServerSocket)
SOCKET* Socket = (SOCKET*)ServerSocket;
ClientSocket = accept(*Socket,0,0);
printf("Client on %d connected\n",ClientSocket);
ServerSocket = socket(PF_INET,SOCK_STREAM,0);
server_address.sin_family = AF_INET;
server_address.sin_port = 4200;
server_address.sin_addr.s_addr = INADDR_ANY;
ThreadHandle = CreateThread(NULL,0,acceptingThreadProcedure,&ServerSocket,0,&ThreadID);
waitTime.tv_sec = 0;
waitTime.tv_usec = 0;
unsigned long BufferSize;
pollingSet = masterSet;
if(pollingSet.fd_count == 0)
RetVal = select(pollingSet.fd_count,&pollingSet,NULL,NULL,&waitTime);
if(RetVal == 0)
for(unsigned int i = 0; i < pollingSet.fd_count; i++)
clientSocket = pollingSet.fd_array[i];
//This was his Idea
BufferSize = ntohl(BufferSize);
LPSTR Buffer = new char[BufferSize];
Buffer[BufferSize] = '\0';
printf("Client %d: %s\n",clientSocket,Buffer);
I've been looking for tutorials that teach it with FD_SET and select but havn't found anything yet.
Does anyone know of a good tutorial?
P.S. The reason I'm looking for something more than what I've found is that the current code (above) doesn't have a way to send data back, and I'm not sure how to add that. Also the code just doesn't seem right (tho I don't know what multi-user code looks like), and it uses 100% system resources.
Alright, thank you much.