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

📄 socketex.h

📁 Socket异步通信,线程,双端队列 网络实时通信。
💻 H
字号:
#if !defined(AFX_SOCKETEX_H__09FE95DC_C52D_4E1E_8F09_E100837725FC__INCLUDED_)
#define AFX_SOCKETEX_H__09FE95DC_C52D_4E1E_8F09_E100837725FC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SocketEx.h : header file
//

/*
本类使用注意事项1:打开Resource.h,添加行:
#define IDP_SOCKETS_INIT_FAILED         103
在应用程序初始化2:InitInstance-函数开头:
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}
*/
#include "Fifo.h"

#include <afxsock.h>		// MFC socket extensions
#define	WM_SOCKETEX	WM_USER+18	//端口接收消息通知窗口。

/////////////////////////////////////////////////////////////////////////////
// CSocketEx command target

class CSocketEx : public CSocket
{
private:
    int   m_nBufLen0;  //缓冲区长度
    char* m_cBufferR;  //缓冲区//注意不使用CByteArray的原因,数据在接收和发送都要用char*!!!
    UINT  m_nLengthR;  //消息长
// Attributes
public:
	BOOL    m_bRecv;	//是接收端口;
	CString	m_strIp;	//绑定端口Ip;
	UINT	m_nPort;	//绑定端口号;
    CFifoY<CByteArray,CString>  m_Fifo2;  //使用该队列的主要原因,生成数据备份,防止同时访问;
	void SetEvent1();	//接收处理事件!
	void SetEvent2();	//发送处理事件!
	void InitEvent();
	static UINT ThreadSocketEx(LPVOID pParam);
	BOOL ActionRecv();
	BOOL ActionSend();
	UINT StarAction();
	void StopAction();
	static CString GetIpAddress(CString& );
	void Init2(CWnd* pOwner=0,UINT nPort = 6801,BOOL bRecv=TRUE,CString strIp="");
protected:
	CWnd*		m_pOwner;
	CWinThread* m_pThread;
	HANDLE      m_hEventAr[3];

    CFifoX<CSocket*>  m_FifoX;  //与端口密切相关的不被外部访问的对象;
// Operations
public:
    CFifoX<CFifoY<CByteArray,CString>*>  m_FifoT;  //将中间临时从:m_Fifo2中弹出的节点添加到本队列,让程序来控制删除;
	CSocketEx(CWnd* pOwner=0,UINT nPort = 6801,BOOL bRecv=TRUE,CString strIp="127.0.0.1");
	virtual ~CSocketEx();

// Overrides
public:
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSocketEx)
	public:
	virtual void OnAccept(int nErrorCode);
	virtual void OnClose(int nErrorCode);
	virtual void OnReceive(int nErrorCode);
	virtual void OnSend(int nErrorCode);
	//}}AFX_VIRTUAL

	// Generated message map functions
	//{{AFX_MSG(CSocketEx)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG

// Implementation
protected:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SOCKETEX_H__09FE95DC_C52D_4E1E_8F09_E100837725FC__INCLUDED_)

⌨️ 快捷键说明

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