📄 tupsocket.cpp
字号:
// TupSocket.cpp : implementation file
//
#include "stdafx.h"
#include "TimeClient.h"
#include "TupSocket.h"
#include "TimeClientDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTupSocket
DWORD
GetLoaclIpAddress(void)
{
union
{
DWORD dwOPC;
char szOPC[4];
};
char szHostName[128];
dwOPC = 0;
if( gethostname ( szHostName, sizeof(szHostName) ) )
{
WSAGetLastError();
}
hostent * pHostent = gethostbyname ( szHostName );
char * pAddr = *(pHostent->h_addr_list);
for( int i=0; i<4; i++ )
{
szOPC[i] = pAddr[3-i];
}
return dwOPC;
}
CTupSocket::CTupSocket(CTimeClientDlg* pMgr)
{
m_pMgr = pMgr;
}
CTupSocket::~CTupSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CTupSocket, CSocket)
//{{AFX_MSG_MAP(CTupSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CTupSocket member functions
void CTupSocket::OnSend(int nErrorCode)
{
if( m_pMgr )
{
m_pMgr->OnSocketSend(this, nErrorCode);
}
CSocket::OnSend(nErrorCode);
}
void CTupSocket::OnAccept(int nErrorCode)
{
CSocket::OnAccept(nErrorCode);
if( m_pMgr )
{
m_pMgr->OnSocketAccept(this, nErrorCode);
}
}
void CTupSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnReceive(nErrorCode);
if( m_pMgr )
{
m_pMgr->OnSocketReceive(this, nErrorCode);
}
}
void CTupSocket::OnClose(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnClose(nErrorCode);
if( m_pMgr )
{
m_pMgr->OnSocketClose(this, nErrorCode);
}
}
void CTupSocket::OnConnect(int nErrorCode)
{
CSocket::OnConnect(nErrorCode);
if( m_pMgr )
{
m_pMgr->OnSocketConnect(this, nErrorCode);
}
}
BOOL CTupSocket::GetConnectIpAddr( char * buffer )
{
CString strPeerAddress;
UINT uPeerPort;
BOOL result = GetPeerName( strPeerAddress, uPeerPort );
strcpy( buffer, (const char*)strPeerAddress );
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -