ServerSocket.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <afxwin.h>
  3. //#include <atlbase.h>
  4. #pragma warning(push)
  5. #pragma warning(disable:4995)
  6. #include <list>
  7. #pragma warning(pop)
  8. #include "CritSection.h"
  9. #include "SocketHandle.h"
  10. #include "SocketServerImpl.h"
  11. #if defined(SOCKHANDLE_USE_OVERLAPPED)
  12. #include "AsyncSocketServerImpl.h"
  13. #endif
  14. typedef std::list<SOCKET> CSocketList;
  15. class CServerSocket :
  16. public ISocketServerHandler
  17. {
  18. #if defined(SOCKHANDLE_USE_OVERLAPPED)
  19. typedef ASocketServerImpl<ISocketServerHandler> CSocketServer;
  20. #else
  21. typedef SocketServerImpl<ISocketServerHandler> CSocketServer;
  22. #endif
  23. friend CSocketServer;
  24. protected:
  25. // ISocketServerHandler
  26. virtual void OnThreadBegin(CSocketHandle* pSH);
  27. virtual void OnThreadExit(CSocketHandle* pSH);
  28. virtual void OnAddConnection(CSocketHandle* pSH, SOCKET newSocket);
  29. virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
  30. virtual void OnConnectionFailure(CSocketHandle* pSH, SOCKET newSocket);
  31. virtual void OnConnectionDropped(CSocketHandle* pSH);
  32. virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
  33. protected:
  34. void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
  35. bool GetDestination(SockAddrIn& addrIn) const;
  36. public:
  37. CServerSocket(void);
  38. ~CServerSocket(void);
  39. public:
  40. int SvrStart(CString strPort);
  41. void SocketStop();
  42. void SocketSend(CSocketHandle &sockHandle, unsigned char *pMsg, int iLength);
  43. protected:
  44. int m_nSockType;
  45. int m_nMode;
  46. BOOL GetClientSocketHandle(CSocketHandle &sockHandle, const SockAddrIn &addr);
  47. void ProcessData(CSocketHandle &sockHandle, const BYTE* pData, DWORD nLen);
  48. int OnCmdProcess(CSocketHandle &sockHandle, void *pData);
  49. int ProcessResDevOnline(CSocketHandle &sockHandle, void *pBuffer);
  50. int ProcessResSingleVarOnline(CSocketHandle &sockHandle, void *pBuffer);
  51. int ProcessResMulVarOnline(CSocketHandle &sockHandle, void *pBuffer);
  52. int ProcessResReadSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
  53. int ProcessResReadMulVarData(CSocketHandle &sockHandle, void *pBuffer);
  54. int ProcessResWriteSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
  55. int PrcocessResWriteMulVarData(CSocketHandle &sockHandle, void *pBuffer);
  56. int ProcessResSoftDog(CSocketHandle &sockHandle, void *pBuffer);
  57. int ProcessResAlarmConfirm(CSocketHandle &sockHandle, void *pBuffer);
  58. int ProcessResReadSpecSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
  59. int ProcessResReadSpecMulVarData(CSocketHandle &sockHandle, void *pBuffer);
  60. public:
  61. CSocketServer m_SocketServer;
  62. };