Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Use of free SocketPro package for creating super client and server applications

, 23 Feb 2002
A set of socket libraries for writing distributed computing applications over the internet
socketpro.zip
netdemo
ClientComponents
MultiSvsSample
SvrComponents
bin
include
lib
Samples
client
DnsSvs
GetHTML
InternetIO
MultiSvsSample
SpeedTest
res
DResolver
Svr
NormalApp
NTSvs
help
trash
SecureSocket
SafeSocket
DNSResolver.exe
GetHtml.exe
IONet.exe
MultipleSvs.exe
MultiSvs.exe
MultiSvsClient.exe
NetBaseR.dll
SafeSocket.exe
SecureSocket.exe
SpeedTest.exe
ClientSocket.dll
DResolver.dll
SBroker.dll
SockFile.dll
fundamental.gif
patterns.gif
NetBaseR.lib
DNSResolver
DNSResolver.vbp
DNSResolver.vbw
frmDNSResolver.frm
frmDNSResolver.frx
frmChatClient.frm
frmChatClient.frx
GETHTML.vbp
GETHTML.vbw
iIO.frm
IONet
IONet.vbp
IONet.vbw
frmMultiSvs.frm
frmMultiSvs.frx
MultiSvs.vbp
MultiSvs.vbw
SafeSocket.vbp
SafeSocket.vbw
SecureSocket.frm
SpeedTest.ico
SpeedTest.aps
SpeedTest.clw
SpeedTest.dsp
SpeedTest.dsw
dlldata.obj
DNS.rgs
DResolver.aps
DResolver.def
DResolver.dsp
DResolver.dsw
DResolver.opt
DResolver.plg
DResolver.tlb
DResolverps.def
DResolverps.exp
DResolverps.lib
DResolverps.mk
DResolver_i.obj
DResolver_p.obj
MultipleSvs.dsp
MultipleSvs.dsw
MultiSvs.dsp
MultiSvs.dsw
MultiSvs.rgs
MultiSvs.tlb
MultiSvsps.def
MultiSvsps.mk
dlldata.obj
SafeSocket.aps
SafeSocket.dsp
SafeSocket.dsw
SafeSocket.plg
SafeSocket.rgs
SafeSocket.tlb
SafeSocketps.def
SafeSocketps.dll
SafeSocketps.exp
SafeSocketps.lib
SafeSocketps.mk
SafeSocket_i.obj
SafeSocket_p.obj
SPassword.rgs
MultipleSvs.exe
MultiSvs.exe
NetBaseR.dll
SafeSocket.exe
// DNS.h : Declaration of the CDNS

#ifndef __DNS_H_
#define __DNS_H_

#include "resource.h"       // main symbols
#include "ClientSocket.h"
#include "ClientSocketCP.h"

#include "SockUtil.h"
#include "SockUtilTemp.h"

class ATL_NO_VTABLE CDNS : 
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CDNS, &CLSID_DNS>,
	public SocketIConnectionPointContainerImpl<CDNS>,
	public SocketIDispatchImpl<IDResolver, &IID_IDResolver, &LIBID_DRESOLVERLib>,
	public CProxy_ISktClientEvents<CDNS>
{
public:
	CDNS()
	{
		m_ClientSocketEvent.m_pDNS=this;
		m_hrDNS=S_OK;
	}
	
	HRESULT FinalConstruct()
	{
		HRESULT hr=m_pIUnknown.CoCreateInstance(__uuidof(SktClient), GetControllingUnknown(), CLSCTX_INPROC_SERVER);
		if(FAILED(hr))
			return hr;
		m_pIUnknownForPointContainer=m_pIUnknown.p;
		m_pIUnknownClientSocket=m_pIUnknown.p;
		m_bstrClients=NULL;
		m_lCount=0;
		m_bstrHostEnt=NULL;
		return m_ClientSocketEvent.DispEventAdvise(m_pIUnknown.p);
	}
	void FinalRelease()
	{
		if(m_bstrClients)
		{
			::SysFreeString(m_bstrClients);
			m_bstrClients=NULL;
		}
		if(m_bstrHostEnt)
		{
			::SysFreeString(m_bstrHostEnt);
			m_bstrHostEnt=NULL;
		}
		HRESULT hr=m_ClientSocketEvent.DispEventUnadvise(m_pIUnknown.p);
	}

DECLARE_REGISTRY_RESOURCEID(IDR_DNS)

DECLARE_PROTECT_FINAL_CONSTRUCT()

DECLARE_GET_CONTROLLING_UNKNOWN()

BEGIN_COM_MAP(CDNS)
	COM_INTERFACE_ENTRY(IDResolver)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
	COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
	COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_pIUnknown.p)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CDNS)
CONNECTION_POINT_ENTRY(DIID__ISktClientEvents)
END_CONNECTION_POINT_MAP()
	
	class CClientSockEvent : public IDispEventSimpleImpl<IDC_SRCSOCKCLIENTEVENT, CClientSockEvent, &__uuidof(_ISktClientEvents)>
	{
	public:
		
	BEGIN_SINK_MAP(CClientSockEvent)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 1, OnDataAvailable, &OnSockEventWinMsgInfo)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 2, OnOtherMessages, &OnSockEventWinMsgInfo)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 3, OnSocketClosed, &OnSockEventFuncInfo)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 4, OnSocketConnected, &OnSockEventFuncInfo)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 5, OnConnecting, &OnSockEventFuncInfo)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 6, OnSendingData, &OnSockEventFuncInfo)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 7, OnGetHostByAddr, &OnSockGetHostByAddr)
		SINK_ENTRY_INFO(IDC_SRCSOCKCLIENTEVENT, __uuidof(_ISktClientEvents), 8, OnGetHostByName, &OnSockGetHostByName)
	END_SINK_MAP()

		virtual HRESULT __stdcall OnDataAvailable(long hSocket, long lBytes, long lError)
		{
			return m_pDNS->OnDataAvailable(hSocket, lBytes, lError);
		}

		virtual HRESULT __stdcall OnOtherMessages(long nMsg, long wParam, long lParam)
		{
			return m_pDNS->OnOtherMessages(nMsg, wParam, lParam);
		}
		virtual HRESULT __stdcall OnSocketClosed(long hSocket, long lError)
		{
			return m_pDNS->OnSocketClosed(hSocket, lError);
		}
		virtual HRESULT __stdcall OnSocketConnected(long hSocket, long lError)
		{
			return m_pDNS->OnSocketConnected(hSocket, lError);
		}
		virtual HRESULT __stdcall OnConnecting(long hSocket, long hWnd)
		{
			return m_pDNS->OnConnecting(hSocket, hWnd);
		}
		virtual HRESULT __stdcall OnSendingData(long hSocket, long lError)
		{
			return m_pDNS->OnSendingData(hSocket, lError);
		}
		virtual HRESULT __stdcall OnGetHostByAddr(LONG nHandle, BSTR bstrHostName, BSTR bstrHostAlias, LONG lError)
		{
			return m_pDNS->OnGetHostByAddr(nHandle, bstrHostName, bstrHostAlias, lError);
		}
		virtual HRESULT __stdcall OnGetHostByName(LONG hHandle, BSTR bstrHostName, BSTR bstrAlias, BSTR bstrIPAddr, LONG lError)
		{
			return m_pDNS->OnGetHostByName(hHandle, bstrHostName, bstrAlias, bstrIPAddr, lError);
		}
		CDNS *m_pDNS;
	};
// IDResolver
public:
	STDMETHOD(GetRtn)(/*[out, retval]*/long *plResult);
	STDMETHOD(AttachSocket)(/*[in]*/IUnknown *pIUnknown);
	STDMETHOD(Count)(/*[out, retval]*/long *plCount);
	STDMETHOD(Clients)(/*[out, retval]*/BSTR *pbstrClients);
	STDMETHOD(GetHostEnt)(/*[out, retval]*/BSTR *pbstrHostEnt);
	STDMETHOD(GetDnsByAddr)(/*[in]*/BSTR bstrAddr);
	STDMETHOD(GetDnsByName)(/*[in]*/BSTR bstrName);
	STDMETHOD(GetCountClients)();
	STDMETHOD(GetClients)();

	HRESULT	SendChunk(void *pBuffer, long nSize, long *plSent);
	HRESULT	RecvChunk(void *pBuffer, long *plRecv);

	virtual HRESULT __stdcall OnDataAvailable(long hSocket, long lBytes, long lError);
	virtual HRESULT __stdcall OnSocketClosed(long hSocket, long lError);
	virtual HRESULT __stdcall OnSocketConnected(long hSocket, long lError);
	virtual HRESULT __stdcall OnConnecting(long hSocket, long hWnd);
	virtual HRESULT __stdcall OnOtherMessages(long nMsg, long wParam, long lParam);
	virtual HRESULT __stdcall OnSendingData(long hSocket, long lError);
	virtual HRESULT __stdcall OnGetHostByAddr(LONG nHandle, BSTR bstrHostName, BSTR bstrHostAlias, LONG lError);
	virtual HRESULT __stdcall OnGetHostByName(LONG hHandle, BSTR bstrHostName, BSTR bstrAlias, BSTR bstrIPAddr, LONG lError);

protected:
	CClientSockEvent	m_ClientSocketEvent;
	CComPtr<IUnknown>	m_pIUnknown;

	BSTR				m_bstrClients;
	long				m_lCount;
	BSTR				m_bstrHostEnt;
	HRESULT				m_hrDNS;
	long				m_hWnd;
	long				m_hSocket;
};

#endif //__DNS_H_

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

Share

About the Author

Yuancai (Charlie) Ye
Web Developer
United States United States
Yuancai (Charlie) Ye, an experienced software engineer, lives in Atlanta, Georgia. He is an expert at OLEDB consumer and created a powerful data accessing libarary at the site http://www.udaparts.com. He has been working at SocketPro written from batching, asynchrony and parallel computation for more than three years. Visual C++, C# and ASP.NET are his favorite development environments.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 24 Feb 2002
Article Copyright 2002 by Yuancai (Charlie) Ye
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid