SocketServerDlg.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SocketServerDlg.h : header file
  2. //
  3. #pragma once
  4. #include <afxwin.h>
  5. #include <atlbase.h>
  6. #pragma warning(push)
  7. #pragma warning(disable:4995)
  8. #include <list>
  9. #pragma warning(pop)
  10. #include "CritSection.h"
  11. #include "SocketHandle.h"
  12. #include "SocketServerImpl.h"
  13. #if defined(SOCKHANDLE_USE_OVERLAPPED)
  14. #include "AsyncSocketServerImpl.h"
  15. #endif
  16. typedef std::list<SOCKET> CSocketList;
  17. // CSocketServerDlg dialog
  18. class CSocketServerDlg : public CDialog,
  19. public ISocketServerHandler
  20. {
  21. #if defined(SOCKHANDLE_USE_OVERLAPPED)
  22. typedef ASocketServerImpl<ISocketServerHandler> CSocketServer;
  23. #else
  24. typedef SocketServerImpl<ISocketServerHandler> CSocketServer;
  25. #endif
  26. friend CSocketServer;
  27. // Construction
  28. public:
  29. CSocketServerDlg(CWnd* pParent = NULL); // standard constructor
  30. virtual ~CSocketServerDlg();
  31. // Dialog Data
  32. enum { IDD = IDD_SOCKETSERVER_DIALOG };
  33. protected:
  34. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  35. // ISocketServerHandler
  36. virtual void OnThreadBegin(CSocketHandle* pSH);
  37. virtual void OnThreadExit(CSocketHandle* pSH);
  38. virtual void OnAddConnection(CSocketHandle* pSH, SOCKET newSocket);
  39. virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
  40. virtual void OnConnectionFailure(CSocketHandle* pSH, SOCKET newSocket);
  41. virtual void OnConnectionDropped(CSocketHandle* pSH);
  42. virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
  43. // Implementation
  44. protected:
  45. HICON m_hIcon;
  46. CString m_strPort;
  47. int m_nMode;
  48. int m_nSockType;
  49. CEdit m_ctlMessage;
  50. CEdit m_ctlMsgList;
  51. CSocketServer m_SocketServer;
  52. void EnableControl(UINT nCtrlID, BOOL bEnable);
  53. void SyncControls();
  54. void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
  55. void _cdecl AppendText(LPCTSTR lpszFormat, ...);
  56. bool GetDestination(SockAddrIn& addrIn) const;
  57. bool SetupMCAST();
  58. // Generated message map functions
  59. virtual BOOL OnInitDialog();
  60. virtual BOOL PreTranslateMessage(MSG* pMsg);
  61. afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
  62. afx_msg void OnPaint();
  63. afx_msg HCURSOR OnQueryDragIcon();
  64. afx_msg void OnDestroy();
  65. DECLARE_MESSAGE_MAP()
  66. public:
  67. afx_msg void OnBnClickedBtnStart();
  68. afx_msg void OnBnClickedBtnStop();
  69. afx_msg void OnBnClickedBtnSend();
  70. };