Thread Creation / Server
-
1)I converted the MFC TCP server into non mfc TCP server using winsock.h. It complies and runs but it does not performs efficiently as the server thread is not created properly in the non mfc statment of _beginthread and CreateThread Plz modify the code so that it runs smoothly thanks 2) what i have to do to make UDP server? 3) how can i change it into mutithreaded server( that accpets connections from many threads?) #include process.h #include windows.h #include iostream.h #include conio.h #include winsock2.h /* _beginthread, _endthread */ #include stddef.h #include stdlib.h unsigned int ServerThread(LPVOID pParam); int main(int argc, char* argv[]) { HANDLE hThread; unsigned long iID; cout<<"!!hello world!!\n"; LPVOID var=0; //unsigned int block=0; //block=ServerThread(var); //Call to the function // _beginthreadex( ServerThread, 0, NULL ); hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE )ServerThread,NULL,0,&iID); //_beginthread(ServerThread, 0, NULL ); // hThread = (HANDLE)_beginthreadex( NULL, 0, &ServerThread, NULL, 0, // &iID ); cout<<"\n\nyahoo"; // while(getch()!=27); // getch(); return 0; } unsigned int ServerThread(LPVOID pParam) { cout<<"Hello from thread"; SOCKET server; //Socket is unsigned int WSADATA wsaData; sockaddr_in local; // Structure variable int wsaret=WSAStartup(0x101,&wsaData); //Initialization if(wsaret!=0) { return 0; }