CSTest/网络客户端/SocketC.h

37 lines
598 B
C
Raw Normal View History

2024-10-17 15:56:43 +08:00
#pragma once
#include<iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <thread>
#include <map>
#include <mutex>
#include <list>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
class SocketC
{
public:
struct MsgInfo
{
int len = 0; //<2F><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
char buff[2048] = {0}; //<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
};
private:
SOCKET sclient = 0;
std::list<MsgInfo*>msgList;
BOOL state = 0;
std::thread rec;
std::mutex msgLock;
bool initSocket();
VOID Receive();
public:
~SocketC();
bool Connect(string IP, UINT Prot);
int Send(const char* Date, int len);
MsgInfo* GetMsg();
void Close();
};