📄 clientsock.cpp
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -