SocketClient.h
Upload User: oadesign
Upload Date: 2013-12-25
Package Size: 265k
Code Size: 2k
Category:

Process-Thread

Development Platform:

Visual C++

  1. #if !defined(AFX_SOCKETCLIENT_H__F25829F8_EFFB_4D11_9D58_889B45139518__INCLUDED_)
  2. #define AFX_SOCKETCLIENT_H__F25829F8_EFFB_4D11_9D58_889B45139518__INCLUDED_
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. // SocketClient.h : header file
  7. //
  8. //
  9. // 注意:
  10. // 在 InitInstance() 函数中调用 AfxSocketInit();函数来初始化网络接口,在
  11. // ExitInstance() 函数中调用 WSACleanup (); 关闭网络接口
  12. //
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSocketClient command target
  15. #include <afxsock.h>
  16. #include "PublicFunction.h"
  17. #define NET_BUFFER_SIZE 4096 // 默认缓冲大小
  18. class CSocketClient : public CSocket
  19. {
  20. // Attributes
  21. public:
  22. BOOL Is_Connected() { return m_bConnected; }
  23. // Operations
  24. public:
  25. CSocketClient ();
  26. virtual ~CSocketClient();
  27. CString GetDigitStrAtHead ( LPCTSTR lpszStr );
  28. int GetResponse ( CString *pcsResponseStr=NULL, BOOL bBlock=TRUE );
  29. BOOL GetResponse ( int nVerifyCode, CString *pcsResponseStr=NULL );
  30. // Overrides
  31. public:
  32. void Disconnect();
  33. int Receive ( char *szBuf, int size, BOOL bBlock=TRUE );
  34. BOOL GetIPAndPortByPasvString ( LPCTSTR lpszPasvString, OUT CString &csIP, OUT USHORT &nPort );
  35. void SetEventOfEndModule ( HANDLE hEvtEndModule );
  36. BOOL Send ( char *data, int size );
  37. BOOL SendString ( LPCTSTR lpszData, ... );
  38. BOOL Connect ( LPCTSTR lpszHost, USHORT nPort );
  39. // ClassWizard generated virtual function overrides
  40. //{{AFX_VIRTUAL(CSocketClient)
  41. //}}AFX_VIRTUAL
  42. // Generated message map functions
  43. //{{AFX_MSG(CSocketClient)
  44. // NOTE - the ClassWizard will add and remove member functions here.
  45. //}}AFX_MSG
  46. // Implementation
  47. protected:
  48. private:
  49. CString m_csResponseHistoryString;
  50. HANDLE m_hEvtEndModule;
  51. BOOL m_bConnected;
  52. };
  53. /////////////////////////////////////////////////////////////////////////////
  54. //{{AFX_INSERT_LOCATION}}
  55. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  56. #endif // !defined(AFX_SOCKETCLIENT_H__F25829F8_EFFB_4D11_9D58_889B45139518__INCLUDED_)