⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sockclient.h

📁 冰人引擎,本2d游戏引擎定位于游戏次中层引擎。他不像CDX等引擎那样
💻 H
字号:
//			Icer Game Engine v1.0
//						Http://www.ngame2000.com
//
//Author:杨冰(源代码之光)
//			E-mail:	iceryeah2000@163.com
//			QQ :	7746642
//
//Module:网络socket客户端
//
//Create:2003-3-6
//Updata:2003-3-14
//
//Describe:提供网络功能部分的客户端管理接口
//Remark:	2003-3-10: Deleting all codes,and rewrite it
//			2003-3-14: Compeling all codes!!

#pragma once

class CSockClient
{
private:
	SOCKET		m_sSocket;					//socket
	DWORD		m_dwProtocol;				//协议

	HANDLE		m_hThread;					//线程句柄
	HANDLE		m_hEvent[2];				//事件

	bool		m_bRunState;				//运行状态
	char		m_strHostIP[128];			//要连接的主机ip
	DWORD		m_dwHostPort;				//要连接的主机端口

	char		m_strIP[128];				//本机ip
	DWORD		m_dwPort;					//本机正使用的端口

	static	bool	ClientThread(LPVOID lpParam);	//客户端消息响应线程
	typedef bool	(*ClientThreadMsg)(CSockClient* pSocket,DWORD dwMessage,DWORD dwValue,DWORD dwErrorCode);
	
	ClientThreadMsg m_pClientThreadMessage;

public:
	CSockClient(void);
	~CSockClient(void);
	
	bool Initialize(void);					//初始化winsock
	void Cleanup(void);						//清除winsock
	
	bool Create(DWORD dwProtocol = SOCK_STREAM);	//创建socket
	bool Connect(const char* strIP, DWORD dwPort);	//连接到主机
	
	bool SendTcp(LPVOID lpBuffer,DWORD dwBufferLenght,DWORD dwFlags = 0);	//发送
	bool RecvTcp(LPVOID lpBuffer,DWORD dwBufferLenght,DWORD dwFlags = 0);	//接受

public:
	void		SetRunState(bool bState)		{m_bRunState = bState;}		//设置运行状态
	bool		GetRunState(void)				{return m_bRunState;}		//获得运行状态

	HANDLE*		GetEvent(void)					{return m_hEvent;}			//获得事件

	SOCKET		GetSocket(void)					{return m_sSocket;}			//获得socket
	void		SetSocket(SOCKET sSocket)		{m_sSocket = sSocket;}		//设置socket

	DWORD		GetBufferLength(void);										//获得数据长读

	void		SetIP(char* strIP)				{strcpy(m_strIP,strIP);}	//设置本机ip
	void		SetPort(DWORD dwPort)			{m_dwPort = dwPort;}		//设置本机使用端口
	char*		GetIP(void)						{return m_strIP;}			//获得本机ip
	DWORD		GetPort(void)					{return m_dwPort;}			//获得本机使用端口

	char*		GetHostIP(void)					{return m_strHostIP;}		//获得主机ip
	DWORD		GetHostPort(void)				{return m_dwHostPort;}		//获得主机端口

	void			SetClientThread(ClientThreadMsg pMessage)	{m_pClientThreadMessage = pMessage;}	//设置客户端消息响应函数指针
	ClientThreadMsg	GetClientThread(void)						{return m_pClientThreadMessage;}		//获得客户端消息响应函数指针
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -