Click here to Skip to main content
14,876,602 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralImageList Control Pin
Rajmathi27-Jan-05 19:57
MemberRajmathi27-Jan-05 19:57 
QuestionHow to split pcl data file to print separate page Pin
hunghn27-Jan-05 19:40
Memberhunghn27-Jan-05 19:40 
Generalproblem in dns query Pin
Ankit Aneja27-Jan-05 19:08
MemberAnkit Aneja27-Jan-05 19:08 
Questionhow to make word so that it doesnt create .tmp Pin
Jetli Jerry27-Jan-05 18:11
MemberJetli Jerry27-Jan-05 18:11 
AnswerRe: how to make word so that it doesnt create .tmp Pin
shaveyourhead27-Jan-05 18:27
Membershaveyourhead27-Jan-05 18:27 
GeneralRe: how to make word so that it doesnt create .tmp Pin
Jetli Jerry27-Jan-05 20:07
MemberJetli Jerry27-Jan-05 20:07 
AnswerRe: how to make word so that it doesnt create .tmp Pin
David Crow28-Jan-05 2:58
MemberDavid Crow28-Jan-05 2:58 
GeneralMulti-user server Pin
Timothy Grabrian27-Jan-05 17:26
professionalTimothy Grabrian27-Jan-05 17:26 
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):

SOCKET ServerSocket;
SOCKADDR_IN server_address;
FD_SET masterSet;
HANDLE ThreadHandle;
DWORD ThreadID;
int RetVal = 0;

DWORD WINAPI acceptingThreadProcedure(LPVOID ServerSocket)
{
	SOCKET* Socket = (SOCKET*)ServerSocket;
	SOCKET ClientSocket;

	while(1)
	{
		ClientSocket = accept(*Socket,0,0);

		FD_SET(ClientSocket,&masterSet);
		printf("Client on %d connected\n",ClientSocket);
	}

	return TRUE;
}
int InitServer()
{
	WSADATA wsaData;
 
	WSAStartup(MAKEWORD(1,0),&wsaData);

	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;	

	bind(ServerSocket,(SOCKADDR*)&server_address,sizeof(SOCKADDR_IN));

	listen(ServerSocket,5);
	
	ThreadHandle = CreateThread(NULL,0,acceptingThreadProcedure,&ServerSocket,0,&ThreadID);

	Sleep(100);

	FD_ZERO(&masterSet);

	FD_SET pollingSet;
	timeval waitTime;
	waitTime.tv_sec = 0;
	waitTime.tv_usec = 0;
	SOCKET clientSocket;
	unsigned long BufferSize;

	while(1) 
	{
		pollingSet = masterSet;
		if(pollingSet.fd_count == 0)
			continue;

		RetVal = select(pollingSet.fd_count,&pollingSet,NULL,NULL,&waitTime);

		if(RetVal == 0)
			continue;

		for(unsigned int i = 0; i < pollingSet.fd_count; i++)
		{
			clientSocket = pollingSet.fd_array[i];

			//This was his Idea
			recv(clientSocket,(LPSTR)&BufferSize,sizeof(BufferSize),0);

			BufferSize = ntohl(BufferSize);
			LPSTR Buffer = new char[BufferSize];

			recv(clientSocket,(LPSTR)Buffer,BufferSize,0);

			Buffer[BufferSize] = '\0';
			printf("Client %d: %s\n",clientSocket,Buffer);
			delete[] 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.
GeneralRe: Multi-user server Pin
trelliot28-Jan-05 2:57
Membertrelliot28-Jan-05 2:57 
Generalexporting global operator+ function from DLL Pin
Jim Crafton27-Jan-05 17:04
MemberJim Crafton27-Jan-05 17:04 
GeneralRe: exporting global operator+ function from DLL Pin
KaЯl27-Jan-05 21:28
MemberKaЯl27-Jan-05 21:28 
GeneralRe: exporting global operator+ function from DLL Pin
Jim Crafton28-Jan-05 3:27
MemberJim Crafton28-Jan-05 3:27 
GeneralRe: exporting global operator+ function from DLL Pin
Bo Hunter28-Jan-05 11:30
MemberBo Hunter28-Jan-05 11:30 
GeneralRe: exporting global operator+ function from DLL Pin
Jim Crafton28-Jan-05 13:47
MemberJim Crafton28-Jan-05 13:47 
GeneralAdd Lib in an Ocx project Pin
rushing27-Jan-05 16:59
Memberrushing27-Jan-05 16:59 
GeneralC++ 4.2 smilie errors...help! Pin
shaveyourhead27-Jan-05 16:47
Membershaveyourhead27-Jan-05 16:47 
GeneralRe: C++ 4.2 smilie errors...help! Pin
Jim Crafton27-Jan-05 17:15
MemberJim Crafton27-Jan-05 17:15 
GeneralRe: C++ 4.2 smilie errors...help! Pin
shaveyourhead27-Jan-05 18:10
Membershaveyourhead27-Jan-05 18:10 
GeneralRe: C++ 4.2 smilie errors...help! Pin
Jim Crafton28-Jan-05 3:17
MemberJim Crafton28-Jan-05 3:17 
GeneralRe: C++ 4.2 smilie errors...help! - Problem Resolved. Thanks Pin
shaveyourhead28-Jan-05 5:28
Membershaveyourhead28-Jan-05 5:28 
GeneralSimple Calculator (Someone PLEASE HELP ME!!!!!) Pin
Atptour27-Jan-05 16:13
MemberAtptour27-Jan-05 16:13 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
Jim Crafton27-Jan-05 17:18
MemberJim Crafton27-Jan-05 17:18 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
DHAPPREP27-Jan-05 17:55
MemberDHAPPREP27-Jan-05 17:55 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
David Crow28-Jan-05 3:12
MemberDavid Crow28-Jan-05 3:12 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
V.27-Jan-05 23:28
professionalV.27-Jan-05 23:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.