clientsock.cpp

来自「数据库监视备份软件客户端通信软件广播状态参数 当前的主库(DWORD)+当前的」· C++ 代码 · 共 75 行

CPP
75
字号
// ClientSock.cpp : implementation file
//

#include "stdafx.h"
#include "client.h"
#include "ClientSock.h"
#include "clientdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CClientSock

CClientSock::CClientSock()
{
	m_buff = new BYTE[8];
}

CClientSock::~CClientSock()
{
	delete m_buff;
}


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

/////////////////////////////////////////////////////////////////////////////
// CClientSock member functions

void CClientSock::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
    
	Receive(m_buff,8);
	CString res;
	res.Format ("%ld",*(int *)(m_buff + 4));
	CTime nowtime =CTime::GetCurrentTime ();
    WritePrivateProfileString("result",nowtime.Format ("%Y年%m月%d日%H:%M:%S"),res,m_dlg->m_log);
    m_dlg->SendMessage (WM_USER_MESSAGE,*(int *)m_buff,*(int *)(m_buff + 4));
	CSocket::OnReceive(nErrorCode);
}

short CClientSock::InitConnect(CString pIPAddress, UINT Port)
{
	if(Create())
	{
		if (Connect(pIPAddress, Port))
		{
			CString strSocketAdd;
			UINT unPort;
			GetSockName(strSocketAdd,unPort);
			GetPeerName(strSocketAdd,unPort);
			return 1;
		}
		else
		{
			return 0;
		}
	}
	else 
	{
		return -1;
	}
}

⌨️ 快捷键说明

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