Click here to Skip to main content
15,896,915 members
Articles / Desktop Programming / MFC

CAsyncProxySocket - CAsyncSocket derived class to connect through proxies

Rate me:
Please Sign up or sign in to vote.
4.73/5 (12 votes)
18 Dec 20012 min read 288.7K   7.7K   79  
This class allows you to establish connections through SOCKS4/5 and HTTP 1.1 proxies.
// MySocket.cpp: Implementierung der Klasse CMySocket.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "stdafx.h"
#include "MySocket.h"

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

//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////

CMySocket::CMySocket()
{

}

CMySocket::~CMySocket()
{

}

void CMySocket::OnReceive(int nErrorCode)
{
	CAsyncProxySocket::OnReceive(nErrorCode);
	if (nErrorCode)
	{
		AfxMessageBox("Fatal error! Network subsystem failed!",MB_ICONSTOP);
		Close();
		return;
	}
	for(;;)
	{
		char buffer;
		int res=Receive(&buffer,1);
		if (res==SOCKET_ERROR || !res)
		{
			if (GetLastError()!=WSAEWOULDBLOCK || !res)
			{
				AfxMessageBox("Error! Connection has been closed!",MB_ICONEXCLAMATION);
				return;
			}
			break;
		}
		CString str;
		m_pResponse->GetWindowText(str);
		str+=buffer;	
		m_pResponse->SetWindowText(str);
	}
}


void CMySocket::OnProxyOperationFailed(int nOpID)
{
	AfxMessageBox("Error! Could not connect through proxy!",MB_ICONEXCLAMATION);
}

void CMySocket::OnListenFinished(unsigned long &retProxyIp,int &retProxyPort)
{
}
	
void CMySocket::OnConnect(int nErrorCode)
{
	CAsyncProxySocket::OnConnect(nErrorCode);
	if (nErrorCode)
	{
		if (GetProxyType())
			AfxMessageBox("Error! Could not connect to proxy server!",MB_ICONEXCLAMATION);
		else
			AfxMessageBox("Error! Could not connect to server!",MB_ICONEXCLAMATION);
		Close();
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions