FrmNetworkF.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //---------------------------------------------------------------------------
  2. #ifndef FrmNetworkFH
  3. #define FrmNetworkFH
  4. //---------------------------------------------------------------------------
  5. #include <Classes.hpp>
  6. #include <Controls.hpp>
  7. #include <StdCtrls.hpp>
  8. #include <Forms.hpp>
  9. #include <winsock2.h>
  10. //---------------------------------------------------------------------------
  11. #define WM_SOCKET_ACCEPT (WM_USER + 100)
  12. #define WM_SOCKET_SELECT (WM_USER + 101)
  13. //---------------------------------------------------------------------------
  14. class TFrmNetwork : public TForm
  15. {
  16. __published: // IDE-managed Components
  17. TMemo *reMsg;
  18. void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
  19. void __fastcall FormDestroy(TObject *Sender);
  20. private: // User declarations
  21. bool FInitialize;
  22. bool FStart;
  23. int FLastErr;
  24. SOCKET FListenSock;
  25. AnsiString FErrorString;
  26. bool __fastcall InitSock();
  27. void __fastcall TermSock();
  28. int __fastcall CloseSocket(SOCKET& ASock);
  29. int __fastcall SocketError(int AError=-1);
  30. public:
  31. bool __fastcall Start();
  32. void __fastcall Stop();
  33. public: // User declarations
  34. __fastcall TFrmNetwork(TComponent* Owner);
  35. void LogWrite(void* ALog);
  36. int LogWrite(int ALogKind, char *AFmt, ...);
  37. void __fastcall OnAcceptClient(TMessage &Msg);
  38. void __fastcall OnSelectClient(TMessage &Msg);
  39. BEGIN_MESSAGE_MAP
  40. MESSAGE_HANDLER(WM_SOCKET_ACCEPT, TMessage, OnAcceptClient)
  41. MESSAGE_HANDLER(WM_SOCKET_SELECT, TMessage, OnSelectClient)
  42. END_MESSAGE_MAP(TForm)
  43. public:
  44. __property int LastError = { read = FLastErr };
  45. __property AnsiString ErrorString = { read = FErrorString };
  46. __property SOCKET Socket = { read = FListenSock };
  47. };
  48. //---------------------------------------------------------------------------
  49. extern PACKAGE TFrmNetwork *FrmNetwork;
  50. //---------------------------------------------------------------------------
  51. #endif