DASocket.h
上传用户:asikq0571
上传日期:2014-07-12
资源大小:528k
文件大小:6k
- // DASocket.h: interface for the CDASrvCnSocket class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_DASOCKET_H__EDEC4EA6_AAAB_4236_B174_5784F387A319__INCLUDED_)
- #define AFX_DASOCKET_H__EDEC4EA6_AAAB_4236_B174_5784F387A319__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #define WM_TCP_SERVER_CONNECTED (WM_USER+200)
- #define WM_TCP_SERVER_RECEIVE (WM_USER+201)
- #define WM_TCP_SERVER_SEND (WM_USER+202)
- #define WM_TCP_SERVER_CLOSED (WM_USER+203)
- #define WM_TCP_CLIENT_CONNECTED (WM_USER+210)
- #define WM_TCP_CLIENT_RECEIVE (WM_USER+211)
- #define WM_TCP_CLIENT_SEND (WM_USER+212)
- #define WM_TCP_CLIENT_CLOSED (WM_USER+213)
- #define WM_UDP_RECEIVE (WM_USER+221)
- #define WM_UDP_SEND (WM_USER+222)
- #define WM_UDP_CLOSED (WM_USER+223)
- /////////////////////////////////////////////////////////////////////////////
- //网络常用操作函数
- int GetLocalHostName(CString &sHostName); //获得本地计算机名称
- int GetIpAddress(const CString & sHostName,CString & sIpAddress);
- CString GetNetError(DWORD error);
- int GetNamebyAddress(const CString &IpAddress,CString &sYouName);//获得对方计算机名称
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////SYSTEMTIME
- // CDASrvCnSocket command target
- class CDAServerSocket;
- class CDASrvCnSocket : public CAsyncSocket
- {
- // Attributes
- public:
- typedef void (CDAServerSocket::*ONNETEVENT)(CAsyncSocket* pSrvCnSocket, int nErrorCode);
- ONNETEVENT m_pEvtReceive;
- ONNETEVENT m_pEvtSend;
- ONNETEVENT m_pEvtOutOfBandData;
- ONNETEVENT m_pEvtAccept;
- ONNETEVENT m_pEvtConnect;
- ONNETEVENT m_pEvtClose;
- // Operations
- public:
- CDASrvCnSocket(CDAServerSocket* pOwner);
- virtual ~CDASrvCnSocket();
- // Overrides
- public:
- int m_nRemoPort;
- CString m_strRemoIP;
- BOOL RecvData(char *pRecvBuffer, int nBufLen, int& dwBytesReaded);
- BOOL SendData(char *pSendBuffer, int nBufLen, int& dwBytesSended);
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CDASrvCnSocket)
- public:
- virtual void OnReceive(int nErrorCode);
- virtual void OnClose(int nErrorCode);
- virtual void OnConnect(int nErrorCode);
- virtual void OnOutOfBandData(int nErrorCode);
- virtual void OnSend(int nErrorCode);
- //}}AFX_VIRTUAL
- // Generated message map functions
- //{{AFX_MSG(CDASrvCnSocket)
- // NOTE - the ClassWizard will add and remove member functions here.
- //}}AFX_MSG
- // Implementation
- protected:
- CDAServerSocket* m_pOwner;
- };
- /////////////////////////////////////////////////////////////////////////////
- typedef CTypedPtrArray<CPtrArray,CDASrvCnSocket*> CDASrvCnSocketArr;
- /////////////////////////////////////////////////////////////////////////////
- // CDAServerSocket command target
- class CDAServerSocket : public CAsyncSocket
- {
- friend class CDASrvCnSocket;
- // Attributes
- public:
- CDASrvCnSocketArr m_arConnections;
- UINT m_nSocketPort;
- CString m_szAddr;
- BOOL PortOpened()
- {
- return m_bHasOpened;
- }
- BOOL SocketConnected()
- {
- return m_bConnected;
- }
- // Operations
- public:
- CDAServerSocket(HWND pOwner);
- virtual ~CDAServerSocket();
- BOOL OpenPort(UINT nSocketPort, const CString szAddr = _T(""));
- void ClosePort();
-
- // Overrides
- public:
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CDAServerSocket)
- public:
- virtual void OnAccept(int nErrorCode);
- //}}AFX_VIRTUAL
- // Generated message map functions
- //{{AFX_MSG(CDAServerSocket)
- // NOTE - the ClassWizard will add and remove member functions here.
- //}}AFX_MSG
- // Implementation
- protected:
- HWND m_hOwner;
- BOOL m_bHasOpened;
- BOOL m_bConnected;
- protected:
- void ReceiveEvt(CAsyncSocket* pSrvCnSocket, int nErrorCode);
- void SendEvt(CAsyncSocket* pSrvCnSocket, int nErrorCode);
- void CloseEvt(CAsyncSocket* pSrvCnSocket, int nErrorCode);
- };
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // CDAClientSocket command target
- class CDAClientSocket : public CAsyncSocket
- {
- // Attributes
- public:
- UINT m_nHostPort;
- CString m_szHostAddr;
- BOOL PortOpened()
- {
- return m_bHasOpened;
- }
- BOOL SocketConnected()
- {
- return m_bConnected;
- }
- // Operations
- public:
- CDAClientSocket(HWND pOwner);
- virtual ~CDAClientSocket();
- BOOL OpenPort(UINT nHostPort, const CString szHostAddr);
- void ClosePort();
- // Overrides
- public:
- BOOL RecvData(char *pRecvBuffer, int nBufLen);
- BOOL SendData(char *pSendBuffer, int nBufLen);
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CDAClientSocket)
- public:
- virtual void OnConnect(int nErrorCode);
- virtual void OnReceive(int nErrorCode);
- virtual void OnSend(int nErrorCode);
- virtual void OnClose(int nErrorCode);
- //}}AFX_VIRTUAL
- // Generated message map functions
- //{{AFX_MSG(CDAClientSocket)
- // NOTE - the ClassWizard will add and remove member functions here.
- //}}AFX_MSG
- // Implementation
- protected:
- HWND m_pOwner;
- BOOL m_bHasOpened;
- BOOL m_bConnected;
- };
- // CDAUDPSocket command target
- class CDAUDPSocket : public CAsyncSocket
- {
- // Attributes
- public:
- UINT m_nLocalPort;
- BOOL PortOpened()
- {
- return m_bHasOpened;
- }
- // Operations
- public:
- CDAUDPSocket(HWND pOwner);
- virtual ~CDAUDPSocket();
- BOOL OpenPort(UINT m_nLocalPort);
- void ClosePort();
- // Overrides
- public:
- // ClassWizard generated virtual function overrides GetSystemTime
- //{{AFX_VIRTUAL(CDAClientSocket)
- public:
- virtual void OnReceive(int nErrorCode);
- virtual void OnSend(int nErrorCode);
- virtual void OnClose(int nErrorCode);
- //}}AFX_VIRTUAL
- // Generated message map functions
- //{{AFX_MSG(CDAClientSocket)
- // NOTE - the ClassWizard will add and remove member functions here.
- //}}AFX_MSG
- // Implementation
- protected:
- HWND m_pOwner;
- BOOL m_bHasOpened;
- };
- /////////////////////////////////////////////////////////////////////////////
- #endif // !defined(AFX_DASOCKET_H__EDEC4EA6_AAAB_4236_B174_5784F387A319__INCLUDED_)