TCPSocket.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "WinSocketSystem.h"
  3. #include "NetOperator.h"
  4. #include <windows.h>
  5. #include "log4z.h"
  6. class TCPServer
  7. {
  8. public:
  9. TCPServer();
  10. ~TCPServer();
  11. public:
  12. int InitNet(const char*ip, int port,INetNotify*pNotify);
  13. void Stop();
  14. int SendData(const char*data);
  15. void SetNotify(INetNotify*pNotify){ m_pNotify = pNotify; }
  16. protected:
  17. static unsigned int __stdcall ListenThread(PVOID param);
  18. static unsigned int __stdcall RecvThread(PVOID param);
  19. SOCKET sockSrv;
  20. SOCKET sockCli;
  21. BOOL m_bexit;
  22. HANDLE _listen_thread;
  23. HANDLE _recv_thread;
  24. INetNotify *m_pNotify;
  25. LockHelper m_tx_send;
  26. };
  27. class TCPClient
  28. {
  29. public:
  30. TCPClient();
  31. ~TCPClient();
  32. public:
  33. int InitNet(const char*ip, int port, INetNotify*pNotify);
  34. void Stop();
  35. int SendData(const char*data);
  36. void SetNotify(INetNotify*pNotify){ m_pNotify = pNotify; }
  37. protected:
  38. static unsigned int __stdcall LoopThread(PVOID param);
  39. SOCKET sockConn;
  40. BOOL m_bexit;
  41. HANDLE _loop_thread;
  42. INetNotify *m_pNotify;
  43. LockHelper m_tx_send;
  44. BOOL m_connected;//Á´½ÓÊÇ·ñÒѾ­Íê³É
  45. };