ClientSocket.h
上传用户:xiejie88
上传日期:2019-07-11
资源大小:3505k
文件大小:2k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // ClientSocket.h: interface for the CClientSocket class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_)
  5. #define AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_
  6. #include <winsock2.h>
  7. #include <mswsock.h>
  8. #include "common/Buffer.h" // Added by ClassView
  9. #include "common/Manager.h"
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif // _MSC_VER > 1000
  13. // Change at your Own Peril
  14. // 'G' 'h' '0' 's' 't' | PacketLen | UnZipLen
  15. #define HDR_SIZE 13
  16. #define FLAG_SIZE 5
  17. enum
  18. {
  19. PROXY_NONE,
  20. PROXY_SOCKS_VER4 = 4,
  21. PROXY_SOCKS_VER5
  22. };
  23. struct socks5req1
  24. {
  25.     char Ver;
  26.     char nMethods;
  27.     char Methods[2];
  28. };
  29. struct socks5ans1
  30. {
  31.     char Ver;
  32.     char Method;
  33. };
  34. struct socks5req2
  35. {
  36.     char Ver;
  37.     char Cmd;
  38.     char Rsv;
  39.     char Atyp;
  40.     unsigned long IPAddr;
  41.     unsigned short Port;
  42.     
  43. //    char other[1];
  44. };
  45. struct socks5ans2
  46. {
  47.     char Ver;
  48.     char Rep;
  49.     char Rsv;
  50.     char Atyp;
  51.     char other[1];
  52. };
  53. struct authreq
  54. {
  55.     char Ver;
  56.     char Ulen;
  57.     char NamePass[256];
  58. };
  59. struct authans
  60. {
  61.     char Ver;
  62.     char Status;
  63. };
  64. class CClientSocket  
  65. {
  66. friend class CManager;
  67. public:
  68. CBuffer m_CompressionBuffer;
  69. CBuffer m_DeCompressionBuffer;
  70. CBuffer m_WriteBuffer;
  71. CBuffer m_ResendWriteBuffer;
  72. void Disconnect();
  73. bool Connect(LPCTSTR lpszHost, UINT nPort);
  74. int Send(LPBYTE lpData, UINT nSize);
  75. void OnRead(LPBYTE lpBuffer, DWORD dwIoSize);
  76. void setManagerCallBack(CManager *pManager);
  77. void setGlobalProxyOption(int nProxyType = PROXY_NONE, LPCTSTR lpszProxyHost = NULL, UINT nProxyPort = 1080, LPCTSTR lpszUserName = NULL, LPCSTR lpszPassWord = NULL);
  78. void run_event_loop();
  79. bool IsRunning();
  80. HANDLE m_hWorkerThread;
  81. SOCKET m_Socket;
  82. HANDLE m_hEvent;
  83. CClientSocket();
  84. virtual ~CClientSocket();
  85. private:
  86. static int m_nProxyType;
  87. static char m_strProxyHost[256];
  88. static UINT m_nProxyPort;
  89. static char m_strUserName[256];
  90. static char m_strPassWord[256];
  91. BYTE m_bPacketFlag[FLAG_SIZE];
  92. bool ConnectProxyServer(LPCTSTR lpszHost, UINT nPort);
  93. static DWORD WINAPI WorkThread(LPVOID lparam);
  94. int SendWithSplit(LPBYTE lpData, UINT nSize, UINT nSplitSize);
  95. bool m_bIsRunning;
  96. CManager *m_pManager;
  97. };
  98. #endif // !defined(AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_)