You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SOCKETPORT_H_INCL__
  2. #define __SOCKETPORT_H_INCL__
  3. #include <errno.h> // Error number definitions
  4. #include <fcntl.h> // File control definitions
  5. #include <stdio.h> // standard input / output functions
  6. #include <stdlib.h>
  7. #include <string.h> // string function definitions
  8. #ifdef __linux__
  9. #include <netdb.h>
  10. #include <netinet/in.h>
  11. #include <sys/ioctl.h>
  12. #include <sys/socket.h>
  13. #include <sys/types.h>
  14. #include <unistd.h> // UNIX standard function definitions
  15. #else
  16. // #include <winsock.h>
  17. #include <windows.h>
  18. #include <winsock2.h>
  19. #include <ws2tcpip.h>
  20. #endif
  21. #include "../transport/transportSocket.h"
  22. #define MAX_HOST_STRING_SIZE 128
  23. // #define DUBUG_COMMUNICATION
  24. // #define CLIENT_SOCKET_NON_BLOCKING
  25. /**
  26. * TODO: Add class description
  27. *
  28. * @author Gagua
  29. */
  30. class clientPort : public transportSocket
  31. {
  32. private:
  33. basicLogCollection * m_pLog;
  34. char m_cHostName[MAX_HOST_STRING_SIZE];
  35. #ifdef __linux__
  36. int m_nSocketFD;
  37. #else
  38. SOCKET m_nSocketFD;
  39. #endif
  40. int m_nPort;
  41. bool m_bKeepAlive;
  42. bool _connect(void);
  43. protected:
  44. int sendBlock(unsigned char * Data, int DataSize);
  45. int recptBlock(unsigned char * Buffer, int * BufferLength);
  46. public:
  47. // Constructor
  48. clientPort();
  49. clientPort(CSTR URI);
  50. clientPort(CSTR Host, int Port, bool KeepALive = true);
  51. // Destructor
  52. virtual ~clientPort();
  53. virtual bool create();
  54. virtual int getRawHandle(void)
  55. {
  56. return m_nSocketFD;
  57. }
  58. bool disconnect(void);
  59. bool connectTo(CSTR Host, int Port);
  60. bool reconnect(void)
  61. {
  62. return _connect();
  63. ;
  64. }
  65. bool isConnected(void)
  66. {
  67. return getConnectionStatus() == CS_CONNECTED;
  68. }
  69. void setKeepAlive(bool Param);
  70. bool getKeepAlive(void)
  71. {
  72. return m_bKeepAlive;
  73. }
  74. CSTR getLocalIp4();
  75. CSTR getRemoteIp4();
  76. };
  77. // TODO: Uncomment the copy constructor when you need it.
  78. // inline socketPort::socketPort(const socketPort& src)
  79. //{
  80. // // TODO: copy
  81. //}
  82. // TODO: Uncomment the assignment operator when you need it.
  83. // inline socketPort& socketPort::operator=(const socketPort& rhs)
  84. //{
  85. // if (this == &rhs) {
  86. // return *this;
  87. // }
  88. //
  89. // // TODO: assignment
  90. //
  91. // return *this;
  92. //}
  93. #endif // __SOCKETPORT_H_INCL__