www.pudn.com > chat-dialog.rar > ClientSocket.cpp


// ClientSocket.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Client1_2.h" 
#include "ClientSocket.h" 
#include "SocketMsg.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CClientSocket 
 
CClientSocket::CClientSocket() 
{ 
} 
 
CClientSocket::~CClientSocket() 
{ 
} 
 
 
// Do not edit the following lines, which are needed by ClassWizard. 
#if 0 
BEGIN_MESSAGE_MAP(CClientSocket, CSocket) 
	//{{AFX_MSG_MAP(CClientSocket) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
#endif	// 0 
 
///////////////////////////////////////////////////////////////////////////// 
// CClientSocket member functions 
 
void CClientSocket::OnReceive(int nErrorCode)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	char chRec[1024]; 
	int nRecLen=1024; 
	int nLen=CSocket::Receive(chRec,nRecLen,0); 
 
	CString sDlg(chRec); 
	CSocketMsg* sockMsg=new CSocketMsg; 
	sockMsg->FormatSocketMsg(sDlg); 
	switch(sockMsg->SystemMsg) { 
	case SM_SENDMESSAGE: 
		m_pParentSock->SendMessage(WM_UPDLGDATA,(WPARAM)chRec,(LPARAM)nLen); 
		break; 
	case SM_CONNECTSEVER: 
		m_pParentSock->SendMessage(WM_SETNEWSOCKET,(WPARAM)chRec,(LPARAM)nLen); 
		break; 
	case SM_CLOSECLIENT: 
		m_pParentSock->SendMessage(WM_CLOSECLIENT,(WPARAM)chRec,(LPARAM)nLen); 
		break; 
	case SM_ALLARM: 
		m_pParentSock->PostMessage(WM_ALLARM); 
		break; 
	default: 
		break; 
	}  
	delete sockMsg; 
	CSocket::OnReceive(nErrorCode); 
}