You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			78 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
			
		
		
	
	
			78 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
| #pragma once
 | |
| #include <QWidget>
 | |
| #include <QDebug>
 | |
| #include <QDateTime>
 | |
| #include <iostream>
 | |
| #include <QThread>
 | |
| #include <qtcpsocket.h>
 | |
| #include "common.h"
 | |
| #include "SyncQueue.h"
 | |
| #include <QTcpServer>
 | |
| 
 | |
| class _TCPSendInfo
 | |
| {
 | |
| public:
 | |
|     std::string pics_name;
 | |
|     std::string result;
 | |
|     std::string num;
 | |
| 
 | |
| 
 | |
| 
 | |
|     _TCPSendInfo()
 | |
|     {
 | |
|         pics_name = "";
 | |
|         
 | |
|     }
 | |
| };
 | |
| 
 | |
| class threadSendTCP : public QThread {
 | |
| public:
 | |
|     QString ip;
 | |
|     int port;
 | |
|     int num = 0;
 | |
| 
 | |
|     threadSendTCP(QObject* o = nullptr) :QThread(o)
 | |
|     {
 | |
|         isLoop = true;
 | |
|     }
 | |
| 
 | |
|     ~threadSendTCP()
 | |
|     {
 | |
|         stop();
 | |
|         _TCPSendInfo TCPSendInfo;
 | |
|         Local_TCP_Info_queue->put(TCPSendInfo);
 | |
|         quit();
 | |
|         wait();
 | |
|     }
 | |
|     void stop();
 | |
| #ifdef __TCPClient
 | |
|     bool connectTCP();
 | |
| #endif
 | |
| protected:
 | |
|     void run();
 | |
| 
 | |
| public:
 | |
|     void init(SyncQueue<_TCPSendInfo>* p_TCP_Info_queue, std::string ip_, int port_);
 | |
|     void start_work();
 | |
|     void sendData(_TCPSendInfo* TCPSendInfo, int Num);
 | |
|     std::vector<int> stringToAscii(const std::string& str);
 | |
| 
 | |
| #ifdef __TCPServer
 | |
| private slots:
 | |
|     void    onNewConnection();
 | |
|     void    onClientConnected();
 | |
|     void    onClientDisconnected();
 | |
| #endif
 | |
| 
 | |
| public:
 | |
|     SyncQueue<_TCPSendInfo>* Local_TCP_Info_queue;
 | |
|     std::atomic_bool isLoop = { 0 };
 | |
| #if defined(__TCPServer) || defined(__TCPClient)
 | |
|     QTcpSocket* mySocket = NULL;
 | |
| #endif
 | |
| #ifdef __TCPServer
 | |
|     QTcpServer *tcpServer = NULL;
 | |
|     QAbstractSocket::SocketState ClientStatus;
 | |
| #endif
 | |
| };
 |