All pastes #1292 Raw Edit

Anonymous

public cpp v1 · immutable
#1292 ·published 2004-10-06 18:50 UTC
rendered paste body
//in global namespace:struct connection {	SOCKET s_client;	sockaddr_in saddr_client;};connection tcon;//in main()//basically this is where the loop is and it accepts connections//it creates a new thread for each, but the socket and sockaddr_in //struct needs to be passed too...// s_client is a SOCKET, client is sockaddr_in (a struct)while(1)	{	    s_client=accept(s_listen,(sockaddr *)&client,&sin_size);		if (s_client != INVALID_SOCKET)		{			tcon.s_client  = s_client;			tcon.saddr_client = client;			CreateThread(NULL,NULL,ConnectionThread,&tcon,NULL,NULL);		}	}// THREAD PROC:DWORD WINAPI ConnectionThread(LPVOID pcon){	connection con = *(connection*)pcon;	AddLog("connection %s:%d",inet_ntoa(con.saddr_client.sin_addr),nPort);		SendHeaders(con.s_client,"/");		char *szData="This is a test\n";	send(con.s_client ,szData,(int)strlen(szData),0);	closesocket(con.s_client);	return 0;}