Serious:Client Server User Tracking
-
I am building a client server user tracking system that will get the username and computer name from the client kernel and send it to server via winsock. I have got the different pieces of the puzzle but now i want to combine them all. So help me out 1) i have the perfect running code of the system call GetComputerName( ). which uses windows.h #include #include int WINAPI WinMain(HINSTANCE h,HINSTANCE p,LPSTR c,int n) { TCHAR szName[256]; // pointer to system information string TCHAR szBuffer[512]; // buffer for expanded string unsigned long iTextLength; TCHAR szSystemInfo[5]; iTextLength = sizeof(szName)/sizeof(TCHAR); // number of characters, not bytes GetComputerName(szName, &iTextLength); iTextLength = sprintf(szBuffer, "Computer name: %s", szName); MessageBox(0, szBuffer, "Computer Name", 0); GetUserName(szName,&iTextLength);//Get User Name iTextLength = sprintf(szBuffer, "User name: %s", szName); MessageBox(0, szBuffer, "User Name", 0); return 0; } 2) I also have the perfect running code of client which uses MFC and sends the status of the client-- that is sends the string from the client which is received at the server. #include "stdafx.h" #include "client.h" #include windows.h #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // The one and only application object UINT sendStatus(); CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; sendStatus(); return nRetCode; } UINT sendStatus() { SOCKET client; WSADATA wsaData; //data structure sockaddr_in serveraddr; //sockaddr_in int wsaret=WSAStartup(0x101,&wsaData); //Initialize wsaret variable if(wsaret!=0) { cout<<"Fail to initialize:"; return 0; } struct hostent *hp; unsigned int addr; struct sockaddr_in server; CString servername="localhost"; SOCKET conn; conn=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(conn==INVALID_SOCKET) return 0; if(inet_addr(servername)==INADDR_NONE) { hp=gethostbyname(servername); } else { addr=inet_addr(servername); hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET); } if(hp==NULL) { cout<<"Fail to get peer address:"; closesocket(conn); return 0; } server.sin_addr.s_addr=*((unsigned long*)hp->h_addr); serve