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.

63 lines
1.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SOCKETPORT_H_INCL__
  2. #define __SOCKETPORT_H_INCL__
  3. #include <stdio.h> // standard input / output functions
  4. #include <stdlib.h>
  5. #include <string.h> // string function definitions
  6. #include <fcntl.h> // File control definitions
  7. #include <errno.h> // Error number definitions
  8. #ifdef __linux__
  9. #include <unistd.h> // UNIX standard function definitions
  10. #include <sys/types.h>
  11. #include <sys/socket.h>
  12. #include <sys/ioctl.h>
  13. #include <netinet/in.h>
  14. #include <netdb.h>
  15. #else
  16. //#include <winsock.h>
  17. #include <winsock2.h>
  18. #include <ws2tcpip.h>
  19. #include <windows.h>
  20. #endif
  21. #include "transportSocket.h"
  22. /**
  23. * TODO: Add class description
  24. *
  25. * @author Gagua
  26. */
  27. class socketPort : public transportSocket {
  28. private:
  29. basicLogCollection *m_pLog;
  30. CSTR m_sHostName;
  31. #ifdef __linux__
  32. struct sockaddr_in serv_addr;
  33. int m_nSocketFD;
  34. #else
  35. SOCKET m_nSocketFD;
  36. #endif
  37. int m_nPort;
  38. bool m_bKeepAlive;
  39. bool _connect( void );
  40. protected:
  41. int sendBlock(unsigned char *Data, int DataSize);
  42. int recptBlock(unsigned char *Buffer, int *BufferLength);
  43. public:
  44. // Constructor
  45. socketPort();
  46. socketPort(CSTR URI);
  47. socketPort(CSTR Host, int Port, bool KeepALive = true);
  48. // Destructor
  49. virtual ~socketPort();
  50. bool disconnect(void);
  51. bool connectTo(CSTR Host, int Port);
  52. bool reconnect(void){ return _connect(); };
  53. bool isConnected(void){ return m_bConnected; };
  54. void setKeepAlive(bool Param);
  55. bool getKeepAlive(void){ return m_bKeepAlive; };
  56. };
  57. #endif // __SOCKETPORT_H_INCL__