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

📄 filesocket.cpp

📁 基于UDP协议的winsock聊天室
💻 CPP
字号:
// FileSocket.cpp : implementation file
//

#include "stdafx.h"
#include "client.h"
#include "FileSocket.h"
#include "ClientDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFileSocket

CFileSocket::CFileSocket()
{
}

CFileSocket::~CFileSocket()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CFileSocket member functions

void CFileSocket::OnAccept(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CClientDlg *pClientDlg = (CClientDlg *)AfxGetMainWnd();
	pClientDlg->OnAccept();
	CSocket::OnAccept(nErrorCode);
}

void CFileSocket::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CClientDlg *pClientDlg = (CClientDlg *)AfxGetMainWnd();
	int nCount=0, nBlock = 8192;
	char *p = new char[nBlock];
	memset(p, 0, nBlock);
	nCount = Receive(p, nBlock);
	if(strcmp(p, "SendOver") == 0)
	{
		pClientDlg->MessageBox("文件接收完毕!");
		this->Close();
	}
	else
	{
		FILE *fp = fopen(pClientDlg->m_strSavePath, "ab");
		long i;
		for(i=0; i<nCount; i++)
		{
			 fputc(p[i],fp);
		}
		fclose(fp);
	}
	CSocket::OnReceive(nErrorCode);
}

void CFileSocket::OnClose(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CClientDlg *pClientDlg = (CClientDlg *)AfxGetMainWnd();
	pClientDlg->OnClose();
	CSocket::OnClose(nErrorCode);
}

void CFileSocket::OnConnect(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CSocket::OnConnect(nErrorCode);
}

⌨️ 快捷键说明

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