Home > Back-end >  The FTP protocol source code for the design and implementation of a comment
The FTP protocol source code for the design and implementation of a comment

Time:10-16

//ClientSocket. CPP: implementation file
//

# include "stdafx. H"//the precompiled header file
# include "TransferDemo. H"
# include "ClientSocket. H"

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

/////////////////////////////////////////////////////////////////////////////
//CClientSocket

CClientSocket: : CClientSocket (CTransferDemoDlg * pdlgMain)
{
M_pdlgMain=pdlgMain;

M_pFile=NULL;
M_pArchiveIn=NULL;
M_pArchiveOut=NULL;
}

CClientSocket: : CClientSocket ()
{
M_pdlgMain=NULL;

M_pFile=NULL;
M_pArchiveIn=NULL;
M_pArchiveOut=NULL;
}

CClientSocket: : ~ CClientSocket ()
{
}


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

/////////////////////////////////////////////////////////////////////////////
//CClientSocket member functions provides

//serialization initialization
Void CClientSocket: : Init ()
{
M_pFile=new CSocketFile (this);
M_pArchiveIn=new CArchive (m_pFile CArchive: : load);
M_pArchiveOut=new CArchive (m_pFile CArchive: : store);
}

Void CClientSocket: : Abort ()
{
If (m_pArchiveOut!=NULL)
{
M_pArchiveOut - & gt; Abort ();
The delete m_pArchiveOut;
M_pArchiveOut=NULL;
}
}

BOOL CClientSocket: : SendMsg (CMessage * pMsg)
{
If (m_pArchiveOut!=NULL)
{
TRY
{
PMsg - & gt; Serialize (* m_pArchiveOut);
M_pArchiveOut - & gt; Flush ();

Return TRUE;
}
The CATCH (CFileException, e)
{
M_pArchiveOut - & gt; Abort ();
The delete m_pArchiveOut;
M_pArchiveOut=NULL;
}
END_CATCH
}

Return FALSE;
}

Void CClientSocket: : ReceiveMsg CMessage * (pMsg)
{
PMsg - & gt; Serialize (* m_pArchiveIn);
}

Void CClientSocket: : OnReceive (int nErrorCode)
{
M_pdlgMain - & gt; ProcessReceive (this);
CSocket: : OnReceive (nErrorCode);
}







//ListenSocket. CPP: implementation file
//

# include "stdafx. H"
# include "TransferDemo. H"
# include "ListenSocket. H"

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

/////////////////////////////////////////////////////////////////////////////
//CListenSocket

CListenSocket: : CListenSocket (CTransferDemoDlg * pdlgMain)
{
M_pdlgMain=pdlgMain;
}

CListenSocket: : CListenSocket ()
{
M_pdlgMain=NULL;
}

CListenSocket: : ~ CListenSocket ()
{
}


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

/////////////////////////////////////////////////////////////////////////////
//CListenSocket member functions provides

Void CListenSocket: : OnAccept (int nErrorCode)
{
M_pdlgMain - & gt; ProcessAccept ();
CSocket: : OnAccept (nErrorCode);
}


# include "stdafx. H"
# include "Message. H"

//the default constructor
CMessage: : CMessage ()
{
M_nType=1;
M_strFileName=_T (" ");
M_dwFileSize=0;
}

//send a general control information is to use the
CMessage: : CMessage (int nType)
{
M_nType=nType;

M_strFileName=_T (" ");
M_dwFileSize=0;
}

//need to send the file name and size using the
CMessage: : CMessage (int nType, cstrings strFileName, dwords dwFileSize)
{
M_nType=nType;

M_strFileName=strFileName;
M_dwFileSize=dwFileSize;
}

CMessage: : ~ CMessage ()
{
}

Void CMessage: : Serialize (CArchive & amp; Ar)
{
If (ar) IsStoring ())
{
Ar & lt;
Ar & lt; Ar & lt; }
The else
{
Ar & gt;> M_nType;

Ar & gt;> M_strFileName;
Ar & gt;> M_dwFileSize;
}
}


//TransferDemo. CPP: Defines the class behaviors for the application. The
//

# include "stdafx. H"
# include "TransferDemo. H"
# include "TransferDemoDlg. H"

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

/////////////////////////////////////////////////////////////////////////////
//CTransferDemoApp

BEGIN_MESSAGE_MAP (CTransferDemoApp CWinApp)
//{{AFX_MSG_MAP (CTransferDemoApp)
//NOTE - the ClassWizard will add and remove the mapping macros here.
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related