www.pudn.com > ChatUseIOCP.rar > DtIpSocket.h


#pragma once 
 
#ifndef _WINSOCK2API_ 
#include 		//standard socket functions. 
#endif 
 
#pragma comment(lib, "Ws2_32.lib") 
 
#define DTIPSOCKET 
 
#ifndef DTSOCKETBASE 
#ifdef EXAMPLE 
#include "../DtLibrary/dtsocketbase.h" 
#else 
#include  
#endif 
#endif 
 
namespace Datatal 
{ 
 
////////////////////////////////////////////////////////////////////////// 
/// 
///		 
///  @class			DtIpSocket - client ip communication class 
///  @version		1.0 
///	 @author		Jonas Gauffin 
///  @homepage		http://www.gauffin.org/cpp 
///	 
///  @brief			client ip communication class, using pure winsock calls  
///  
///  @since 2003-02-28	jg	File created 
/// 
////////////////////////////////////////////////////////////////////////// 
class DtIpSocket : public DtSocketBase 
{ 
//	friend function ThreadFunc; 
 
public: 
	DtIpSocket(void); 
	~DtIpSocket(void); 
 
	/// Connect to a server. the function also starts the thread. 
	/// @param HostName ip/hostname 
	/// @param Remoteport tcp port. 
	/// @returns true if success. 
	void Connect(const char* szHostName, int nRemotePort); 
	void Connect(); 
 
	/// Disconnects from the server 
	bool Disconnect(bool bStopThread = false); 
 
	/// Returns the type of communicationclass that currently are used. 
	/// @returns The type of the current communictation. TCPIP or SERIAL 
	const char* GetTypeName() { return "TCPIP"; }; 
 
	/// Set ip/hostname of the server that we should connect to. 
	/// @param HostName ip/hostname 
	void SetRemoteHost(const char* szHostName); 
 
	/// Set port of the server that we should connect to. 
	/// @param Remoteport tcp port. 
	void SetRemotePort(int RemotePort); 
 
	/// Disable nagle algorithm to get ACK for all packets, MUST be done before connect. 
	void DisableNagle(); 
 
	/// Disable winsocks internal sendbuffer and use own buffering only. 
	void DisableSendBuffer(); 
 
	/// Disable winsocks internal recvbuffer and use own buffering only. 
	void DisableRecvBuffer(); 
 
protected: 
 
	SOCKET				m_sdClient; 
	bool				m_bDisableNagle;	/// Disable nagle algorithm 
	bool				m_bDisableRecvBuf;	/// Disable winsocks internal recv buffer 
	bool				m_bDisableSendBuf;	/// Disable winsocks internal send buffer. 
 
	//Addressing 
	int					m_nRemotePort;		/// Port that we should connect to 
	char				m_szRemoteHost[128];/// Host that we should connect to. 
 
	void ThreadFunc(HANDLE hStopEvent); 
}; 
 
}; //namespace.