CSTest/网络客户端/SocketC.h
2024-10-17 15:56:43 +08:00

37 lines
598 B
C++

#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; //ÄÚÈݳ¤¶È
char buff[2048] = {0}; //ÏûÏ¢ÄÚÈÝ
};
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();
};