多线程winsock2客户端

多线程winsock2客户端

本文介绍了多线程winsock2客户端/服务器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个winsock2客户端服务器应用程序,其中服务器应该是可以接受多个客户端的多线程.我是c ++的新手,使用单线程已完成.现在我想连接多个客户端.我非常多线程实现的新手.任何人都可以帮助我...........在此先感谢

这是我的一部分代码
:::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::

I am developing a winsock2 client server application in which server should be a multithreaded that can accept multiple clients.I am new new to c++.Using single thread it is all done.Now i want to connect multiple clients.I am very new to multithreading implementation.Can any one help me........... thanks in advance

Here is my part of code
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

int					ErrorNo;
class FTP_Server
{
private:
   WSADATA              wsaData;
   SOCKET               ListeningSocket;
   SOCKET               NewConnection;
   SOCKADDR_IN          ServerAddr;
   SOCKADDR_IN          ClientAddr;
   char					SERVER_IP[16];
   char					U_Name[10];
   char					Password[40];
   char					C_U_Name[10];
   char					C_Password[10];
   int 					PORT_NO;
   int                  Len;
   char                 ReceiveBuf[1024];
   char                 BUFFER[1024];
   int                  BufLength;

   FILE					*READCONF;
   FILE					*SENDFILE;
   long					lSize;
   char                 PATH[100];
   WIN32_FIND_DATA		ffd;
   LARGE_INTEGER		filesize;
   TCHAR				szDir[MAX_PATH];
   size_t				length_of_arg;
   HANDLE				hFind ;
   DWORD				dwError;
   wchar_t				lpStr[1024];
   char					mbstr[1024];
   int					noOfFiles;
   char					*sharedFiles[50];
   map<string ,int>     CSOptions;
public:
	FTP_Server()
	{
		BufLength = 1024;
		Len = sizeof(ClientAddr);
		CSOptions["CommRequest"] = 1;
		CSOptions["getSharedFiles"] = 2 ;
		CSOptions["getPropFiles"] = 3;
		CSOptions["getFile"] = 4;
		CSOptions["EXIT"] = 5;

	}
   void ReadConfigurationFile(void);//reading configuration data from a file
   void CreateSocket(void); //socket creation 
   void BindSocket(void);//Bind and listen
   void AcceptClient(void);//Accept 
   int  AuthenticateClient(void);//authentication Uname Psss
   void AcceptRequest(void);//Incoming requests
   void CommunicationWithClients(void);
   void SendSharedFiles(void);
   void SendPropertiesOfFile(void);
   void SendFile(void);
   void CloseSockets(void);
   void CleanUp(void);
   void CommunicateWithClients(void);
   ~FTP_Server(){}
};

推荐答案


这篇关于多线程winsock2客户端/服务器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 21:55