mysocket.cpp

来自「实现文件传书是很有用的一个传书软件是大势的比口欧式」· C++ 代码 · 共 60 行

CPP
60
字号
// MySocket.cpp : implementation file
//

#include "stdafx.h"
#include "FileTransferClient.h"
#include "MySocket.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

HANDLE hMessageCome[NumOfThread];

// CMySocket

CMySocket::CMySocket():Thdidx(0)
{
}

CMySocket::~CMySocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CMySocket, CAsyncSocket)
	//{{AFX_MSG_MAP(CMySocket)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

/////////////////////////////////////////////////////////////////////////////
// CMySocket member functions
//OnConnect重载函数
void CMySocket::OnConnect(int nErrorCode)
{
	static Connected=0;
	if(nErrorCode==0)
	{
		Thdidx=++Connected;
		this->AsyncSelect(FD_READ|FD_CONNECT);
		if(Connected==NumOfThread)
		{
			Connected=0;
			AfxMessageBox("Connect success");
		}
	}
	CAsyncSocket::OnConnect(nErrorCode);
}

//OnReceive重载函数
void CMySocket::OnReceive(int nErrorCode)
{
	//设置文件接收对象,通知线程可以接收数据
	SetEvent(hMessageCome[Thdidx-1]);
	CAsyncSocket::OnReceive(nErrorCode);
}

⌨️ 快捷键说明

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