broadcast.h 507 B

123456789101112131415161718192021222324252627282930
  1. #ifndef __BROADCAST_H__
  2. #define __BROADCAST_H__
  3. #include <QObject>
  4. #include <QJsonObject>
  5. #include <unistd.h>
  6. #include <arpa/inet.h>
  7. #include <sys/socket.h>
  8. class Broadcast : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit Broadcast(const int port, QObject *parent = nullptr);
  13. ~Broadcast();
  14. int write(const QJsonObject &json);
  15. protected:
  16. bool init(const int port);
  17. private:
  18. int sockfd;
  19. struct sockaddr_in broadcast_addr;
  20. int broadcast_enable = 1;
  21. };
  22. #endif // BROADCAST_H