diff --git a/v1.3.0/fuwu.cpp b/v1.3.0/fuwu.cpp new file mode 100644 index 0000000..07da9a9 --- /dev/null +++ b/v1.3.0/fuwu.cpp @@ -0,0 +1,230 @@ +// io +#include + +// sock +#include +#pragma comment (lib,"WS2_32.lib") + +// tread +#include +#include + +// string +#include + +using namespace std; + +// global +bool has_treading=false; // accept-ing +int size=0; // listen size +SOCKET serversocket; // server socket + +thread t[10]; // thread +bool runt[10]; // is run thread + +char sendText[255]; // send text +bool threadSend[10]; // can send to cilent(in the thred) + +int uploadSize=0; // upload size +bool canUpload(){ + for (int i=0;i break + return false; + } + } + return true; +} + +bool uploadText(string text){ + if (!canUpload()){ + return false; + } +// cout<<"comming uploadText"< send +// cout<<"send!"<=10){ // 先判断消息是否堵塞 + char tips[]="[发的太快了,被抛弃了]"; + send(c,tips,strlen(tips),0); + } else { // 先判断有没有在接受申请的进程 + for (int j=0;j<10;j++){ // 找出isupload中第一个为false(空闲的线程) + if (!isupload[j]){ + isupload[j]=true; // 有消息在发送 + try{ // 开启线程 + upload[j].detach(); + } catch (system_error err){} + upload[j]=thread(uploadTread,recvBuff,j); + break; + } + // cout< +#include +using namespace std; + +// socket +#include +#pragma comment (lib,"WS2_32.lib") + +// tread +#include +#include + +// pause +#include + + +SOCKET clientsocket; + +int recvClient(){ + while (true){ + int iRet; + char recvBuff[225]; + iRet=recv(clientsocket,recvBuff,225,0); + if (iRet <= 0){ + cout << "服务端关闭连接" << endl; + system("pause"); + exit(0); + } + cout <<"\t"<>name; + + char buff_front[7]; // 发送的前几个字符 + strcpy(buff_front,name); + strcat(buff_front,":"); + //发送数据 + + thread recvThread(recvClient); + + while (true) + { + char s[255-7]; + cin.getline(s,255-7); + + char Buff[255]; + strcpy(Buff,buff_front); + strcat(Buff,s); + + if (strcmp(Buff,buff_front)==0){ + strcpy(Buff,""); // clear + strcat(Buff,"Welcome user "); + strcat(Buff,name); + send(clientsocket, Buff, strlen("Welcome user ")+6, 0); + continue; + } + + send(clientsocket, Buff, 255, 0); + } + +} diff --git a/v1.3.0/kehu.exe b/v1.3.0/kehu.exe new file mode 100644 index 0000000..8dd12a4 Binary files /dev/null and b/v1.3.0/kehu.exe differ