1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #pragma once
- #include <afxwin.h>
- //#include <atlbase.h>
- #pragma warning(push)
- #pragma warning(disable:4995)
- #include <list>
- #pragma warning(pop)
- #include "CritSection.h"
- #include "SocketHandle.h"
- #include "SocketServerImpl.h"
- #if defined(SOCKHANDLE_USE_OVERLAPPED)
- #include "AsyncSocketServerImpl.h"
- #endif
- typedef std::list<SOCKET> CSocketList;
- class CServerSocket :
- public ISocketServerHandler
- {
- #if defined(SOCKHANDLE_USE_OVERLAPPED)
- typedef ASocketServerImpl<ISocketServerHandler> CSocketServer;
- #else
- typedef SocketServerImpl<ISocketServerHandler> CSocketServer;
- #endif
- friend CSocketServer;
- protected:
- // ISocketServerHandler
- virtual void OnThreadBegin(CSocketHandle* pSH);
- virtual void OnThreadExit(CSocketHandle* pSH);
- virtual void OnAddConnection(CSocketHandle* pSH, SOCKET newSocket);
- virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
- virtual void OnConnectionFailure(CSocketHandle* pSH, SOCKET newSocket);
- virtual void OnConnectionDropped(CSocketHandle* pSH);
- virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
- protected:
- void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
- bool GetDestination(SockAddrIn& addrIn) const;
- public:
- CServerSocket(void);
- ~CServerSocket(void);
- public:
- int SvrStart(CString strPort);
- void SocketStop();
- void SocketSend(CSocketHandle &sockHandle, unsigned char *pMsg, int iLength);
- protected:
- int m_nSockType;
- int m_nMode;
- BOOL GetClientSocketHandle(CSocketHandle &sockHandle, const SockAddrIn &addr);
- void ProcessData(CSocketHandle &sockHandle, const BYTE* pData, DWORD nLen);
- int OnCmdProcess(CSocketHandle &sockHandle, void *pData);
- int ProcessResDevOnline(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResSingleVarOnline(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResMulVarOnline(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadMulVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResWriteSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
- int PrcocessResWriteMulVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResSoftDog(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResAlarmConfirm(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadSpecSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadSpecMulVarData(CSocketHandle &sockHandle, void *pBuffer);
- public:
- CSocketServer m_SocketServer;
- };
|