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

tcpsocket.h 688 B

8 years ago
12345678910111213141516171819202122232425262728293031323334
  1. #ifndef TCPSOCKET_H
  2. #define TCPSOCKET_H
  3. #include <string>
  4. using namespace std;
  5. class TcpSocket
  6. {
  7. public:
  8. TcpSocket();
  9. TcpSocket(int socket);
  10. ~TcpSocket();
  11. public:
  12. bool connect(const string& ip, int port);
  13. void disconnect();
  14. public:
  15. int send(const void* data, int size);
  16. /**
  17. * @brief recv 阻塞等待数据
  18. * @param data 接收缓冲区
  19. * @param size 最大接收字节数
  20. * @param msTimeout 接收超时(毫秒)
  21. * @return 接收到的字节数;超时返回-1,其他错误返回-2
  22. */
  23. int recv(void* data, int size, int msTimeout = 1000);
  24. private:
  25. int mSocket=-1;
  26. string mPeerIp;
  27. };
  28. #endif // TCPSOCKET_H

mac下的“飞秋”大多数只是飞鸽传书协议,而且未发现令人满意的开源项目,所以基于c++与qt实现了基础的飞秋协议。

Contributors (1)