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

📄 wzdsock.h

📁 E:Visual_C__MFC扩展编程实例 实例51:使用套接字与任意的应用程序通信
💻 H
字号:
// WzdSock.h: interface for the CWzdServer and CWzdClient class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WZDSOCK_H__81CE0F20_8C16_11D2_A18D_99620BDF6820__INCLUDED_)
#define AFX_WZDSOCK_H__81CE0F20_8C16_11D2_A18D_99620BDF6820__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxsock.h>
#include <afxtempl.h>
#include "WzdQue.h"

#define WM_NEW_MESSAGE WM_USER+1
#define WM_DONE_MESSAGE WM_USER+2

//////////////////////////////////////////////////////////////////////
// Thread data
//////////////////////////////////////////////////////////////////////
typedef struct t_SENDDATA
{
	CSocket *pSocket;
	LPSTR lpBuf;
	int len;
} SENDDATA;

typedef CMap<int,int,CSocket *,CSocket *> SOCKMAP;
typedef struct t_RECVDATA
{
	CSocket *pSocket;
	int hdrSz;
	int bodyPos;
	CWzdQueue *pQueue;
	CWnd *pWnd;
	UINT id;
} RECVDATA;

//////////////////////////////////////////////////////////////////////
// CWzdServer
//////////////////////////////////////////////////////////////////////


class CWzdServer : public CSocket
{
public:
	CWzdServer(){};
	virtual ~CWzdServer();

	BOOL Open(UINT nPort);
	void CloseEx();
	void SendEx(int id, LPSTR lpBuf, int len);
	void ListenEx(int hdrSz, int bodyPos, CWzdQueue *pQueue, CWnd *pWnd, UINT id);

// Overrides
	virtual void OnAccept ( int nErrorCode );

private:
	int m_id;
	SENDDATA m_SendData;
	RECVDATA m_RecvData;
	SOCKMAP m_mapSockets;
};

//////////////////////////////////////////////////////////////////////
// CWzdClient
//////////////////////////////////////////////////////////////////////

class CWzdClient : public CSocket
{
public:
	CWzdClient() {};
	virtual ~CWzdClient() {};

	BOOL Open(LPCTSTR lpszHostAddress, UINT nHostPort);
	void SendEx(LPSTR lpBuf, int len);
	void ListenEx(int hdrSz, int bodyPos, CWzdQueue *pQueue, CWnd *pWnd, UINT id);
private:
	SENDDATA m_SendData;
	RECVDATA m_RecvData;
};

//////////////////////////////////////////////////////////////////////
// Threads
//////////////////////////////////////////////////////////////////////
UINT SendThread( LPVOID pParam );
UINT RecvThread( LPVOID pParam );

#endif // !defined(AFX_WZDSOCK_H__81CE0F20_8C16_11D2_A18D_99620BDF6820__INCLUDED_)

⌨️ 快捷键说明

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