⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientsocket.cpp

📁 GPRS拨号包括CMNET,CMWAP ,用程序实现WAP访问.
💻 CPP
字号:
// ClientSocket.cpp : implementation file
//

#include "stdafx.h"
#include "DialTest.h"
#include "ClientSocket.h"
#include "DialTestDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CClientSocket

CClientSocket::CClientSocket(CDialog* pDlg)
{
	m_pDlg = pDlg;
}

CClientSocket::~CClientSocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CClientSocket, CAsyncSocket)
	//{{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
#define MAX_RECEIVE_BUF 4096
	char szData[MAX_RECEIVE_BUF+1];
	int nRecv = 0;

	if (nErrorCode == 0)
	{
		nRecv = this->Receive(szData, MAX_RECEIVE_BUF);
		if (nRecv > 0 && nRecv <= MAX_RECEIVE_BUF)
		{
			szData[nRecv] = '\0';
			if (m_pDlg)
			{
				((CDialTestDlg*)m_pDlg)->AddReceiveData(szData, nRecv);
			}
			m_strReceived += szData;

			if (m_strReceived.Find("</wml>") > 0)
			{
				Close();
				if (m_pDlg)
				{
					((CDialTestDlg*)m_pDlg)->DoParsePage(m_strReceived);
				}
			}
		}
		if (nRecv == 0)
		{
			Close();
		}

	}



	CAsyncSocket::OnReceive(nErrorCode);
}

void CClientSocket::OnConnect(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (nErrorCode != 0)
	{
		if (m_pDlg)
		{
			((CDialTestDlg*)m_pDlg)->MessageBox("OnConnect 连接 10.0.0.172:80 失败");
		}
	}
	else
	{
		Send(m_strSendContent, m_strSendContent.GetLength());
		if (m_pDlg)
		{
			CString strSplit = "\r\n**********************************\r\n";
			((CDialTestDlg*)m_pDlg)->AddReceiveData(m_strSendContent, m_strSendContent.GetLength());
			((CDialTestDlg*)m_pDlg)->AddReceiveData(strSplit, strSplit.GetLength());
		}
	}

	CAsyncSocket::OnConnect(nErrorCode);
}

void CClientSocket::OnClose(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (m_pDlg)
	{
		((CDialTestDlg*)m_pDlg)->DoParsePage(m_strReceived);
	}
	
	CAsyncSocket::OnClose(nErrorCode);
}

void CClientSocket::ConnectAndSend(LPCTSTR lpszBindIp, LPCTSTR lpszConnectIp, USHORT nConnectPort, LPCTSTR lpszSendContent)
{
	Close();
	Create(0, SOCK_STREAM);
	Bind(0, lpszBindIp);
	Connect(lpszConnectIp, nConnectPort);
	CString strSplit = "\r\n\r\n\r\n==========================================\r\n";
	if (m_pDlg)
	{
		((CDialTestDlg*)m_pDlg)->AddReceiveData(strSplit, strSplit.GetLength());
	}

	m_strSendContent = lpszSendContent;
}

⌨️ 快捷键说明

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