CSTest/网络服务端/网络服务端.cpp

74 lines
1.0 KiB
C++
Raw Permalink Normal View History

2024-10-17 15:56:43 +08:00
#include "SocketS.h"
2024-10-23 23:58:57 +08:00
//#include "cst.h"
2024-10-17 15:56:43 +08:00
#include <iostream>
struct clienMsg
{
int myName;
int snedName;
int code;
int len;
char buf[1024];
};
2024-10-23 23:58:57 +08:00
struct MsgHead
{
int MyIndex = 0;
int SendIndex = 0;
int bufLen = 0;
time_t tm = 0;
//char token[34] = { 0 };
};
struct msgInfo
{
int buflen = 0;
char buf[10240] = { 0 };
};
2024-10-17 15:56:43 +08:00
std::map<int/*name*/, int/*index*/> clienMap;
std::map<int/*index*/, int/*name*/> clienIndex;
SocketS s(1);
2024-10-23 23:58:57 +08:00
int cont = 0;
VOID closeFunc(int index)
{
if (clienIndex.find(index) != clienIndex.end())
{
clienMap.erase(clienIndex[index]);
clienIndex.erase(index);
}
}
VOID recvFunc(int index, char* buf, int len)
{
//s.CloseClien(index);
//cout << buf;
string str = buf;
s.SendStr(index, str);
2024-10-23 23:58:57 +08:00
}
2024-10-17 15:56:43 +08:00
int main(void)
{
2024-10-23 23:58:57 +08:00
//s.SetRecvFunc([&tt](SocketS::msgInfo info) {return tt.ppp(info); });
//s.Creat(6666);
//s.Close();
2024-10-23 23:58:57 +08:00
s.SetCloseFunc(closeFunc);
s.SetRecvFunc(recvFunc);
if (s.Creat(6666))
{
cout << "服务器创建成功\n";
}
else
{
cout << "服务器创建失败\n";
}
2024-10-23 23:58:57 +08:00
while(1)
2024-10-17 15:56:43 +08:00
{
2024-10-23 23:58:57 +08:00
Sleep(100);
2024-10-17 15:56:43 +08:00
}
return 0;
}