84 lines
1.8 KiB
C++
84 lines
1.8 KiB
C++
// TickerSocket.cpp : implementation file
|
|
|
|
#include "stdafx.h"
|
|
#include "TickerSocket.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTickerSocket
|
|
|
|
CTickerSocket::CTickerSocket()
|
|
{
|
|
m_byteReceive = NULL;
|
|
}
|
|
|
|
CTickerSocket::~CTickerSocket()
|
|
{
|
|
if (m_byteReceive)
|
|
delete m_byteReceive;
|
|
}
|
|
|
|
BOOL CTickerSocket::Create(LPSTR szAddress, UINT nPortNo, CWnd* pParentWnd, int nReceiveSize)
|
|
{
|
|
if (!CSocket::Create())
|
|
{
|
|
#ifndef _DEBUG // debug version in CTickerSocket.cpp
|
|
AfxMessageBox("Error : CSocket::Create() in socket");
|
|
#endif
|
|
return FALSE;
|
|
}
|
|
|
|
if (!CSocket::Connect(szAddress, nPortNo))
|
|
{
|
|
CSocket::Close();
|
|
#ifndef _DEBUG // debug version in CTickerSocket.cpp
|
|
AfxMessageBox("Error : CSocket::Connect() in socket");
|
|
#endif
|
|
return FALSE;
|
|
}
|
|
|
|
m_wndParent = pParentWnd;
|
|
m_nReceiveLen = 0;
|
|
|
|
m_nReceiveSize = nReceiveSize;
|
|
m_byteReceive = new BYTE[m_nReceiveSize];
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Do not edit the following lines, which are needed by ClassWizard.
|
|
#if 0
|
|
BEGIN_MESSAGE_MAP(CTickerSocket, CSocket)
|
|
//{{AFX_MSG_MAP(CTickerSocket)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
#endif // 0
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTickerSocket member functions
|
|
|
|
void CTickerSocket::OnReceive(int nErrorCode)
|
|
{
|
|
// µ¥ÀÌÅÍ Àбâ
|
|
m_nReceiveLen = Receive(m_byteReceive, m_nReceiveSize);
|
|
|
|
// ÅëÁö : SCM_RECEIVE
|
|
if( m_nReceiveLen > 0)
|
|
m_wndParent->SendMessage(SCM_RECEIVE, WPARAM(nErrorCode), LPARAM(this));
|
|
|
|
CSocket::OnReceive(nErrorCode);
|
|
}
|
|
|
|
void CTickerSocket::OnClose(int nErrorCode)
|
|
{
|
|
m_wndParent->SendMessage(SCM_CLOSE, WPARAM(nErrorCode), LPARAM(this));
|
|
|
|
CSocket::OnClose(nErrorCode);
|
|
}
|