clientsocket.h 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef CLIENTSOCKET_H
  2. #define CLIENTSOCKET_H
  3. #include <QObject>
  4. #include <QtNetwork>
  5. #define CLIENT_ID "cliId"
  6. class ClientSocket : public QObject
  7. {
  8. Q_OBJECT
  9. Q_PROPERTY(bool udpOnly READ UdpOnly WRITE setUdpOnly)
  10. public:
  11. explicit ClientSocket(QObject *parent = 0);
  12. ~ClientSocket();
  13. bool UdpOnly();
  14. void setUdpOnly(bool);
  15. private:
  16. void startTcpCommunication(const QHostAddress& address);
  17. void writeLog(QString log);
  18. signals:
  19. void clientLog(QString log);
  20. void connected(QString address);
  21. private slots:
  22. void udpGetData();
  23. void readServerTcpData();
  24. void connectedToServer();
  25. public slots:
  26. void start();
  27. void stop();
  28. void sendToServer(QString msg);
  29. private:
  30. QUdpSocket* iUdpDiscoverySocket;
  31. QTcpSocket* iCommTcpSocket;
  32. bool udpOnly;
  33. QString iServerAddress;
  34. };
  35. #endif // CLIENTSOCKET_H