|  | @@ -61,17 +61,15 @@ int rabbitClient::sendMsg(const std::string str)
 | 
	
		
			
				|  |  |      printf("-------------rabbit client sendmsg----------------------\n");
 | 
	
		
			
				|  |  |      int iRet;
 | 
	
		
			
				|  |  |      amqp_basic_properties_t properties = {};
 | 
	
		
			
				|  |  | -    std::string msg = this->readImg(str);
 | 
	
		
			
				|  |  | -    CMessage cmsg(msg, properties, objRabbitmq->routing_keys_name);
 | 
	
		
			
				|  |  | +    CMessage cmsg(str, properties, objRabbitmq->routing_keys_name);
 | 
	
		
			
				|  |  |      iRet = objRabbitmq->PublishMessage(cmsg, ErrorReturn);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      if(iRet!=0){
 | 
	
		
			
				|  |  |          cout<<"Send Rabbitmq publish Message : "<<ErrorReturn <<endl;
 | 
	
		
			
				|  |  |          disconnect_index++;
 | 
	
		
			
				|  |  |          if(disconnect_index == 15){
 | 
	
		
			
				|  |  |              connection_state = false;
 | 
	
		
			
				|  |  |              disConnect();
 | 
	
		
			
				|  |  | -            emit restart_send_client_signal();
 | 
	
		
			
				|  |  | +            emit restart_send_client_signal();//信号
 | 
	
		
			
				|  |  |              return -1;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }else {
 | 
	
	
		
			
				|  | @@ -100,27 +98,23 @@ int rabbitClient::recvMsg()
 | 
	
		
			
				|  |  |              if(disconnect_index == 15){
 | 
	
		
			
				|  |  |                  connection_state = false;
 | 
	
		
			
				|  |  |                  disConnect();
 | 
	
		
			
				|  |  | -                emit restart_recv_client_signal();
 | 
	
		
			
				|  |  | +                emit restart_recv_client_signal();//信号
 | 
	
		
			
				|  |  |                  return -1;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          disconnect_index = 0;
 | 
	
		
			
				|  |  |          cout<<str<<endl;
 | 
	
		
			
				|  |  |          printf("------------recvClient recvMsg-------------------\n");
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if(str!="") emit recv(QString::fromStdString(str));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        if(str!="")
 | 
	
		
			
				|  |  | +            emit sendmsg_recvclientToRecvstate(QString::fromStdString(str));//信号
 | 
	
		
			
				|  |  |          QThread::sleep(1);
 | 
	
		
			
				|  |  | -        //cout<<"recv"<<endl;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      return 0;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  | - * @brief: init recvClient
 | 
	
		
			
				|  |  | + * @brief: init recvClient(初始化接收客户机)
 | 
	
		
			
				|  |  |   * @param: void
 | 
	
		
			
				|  |  |   * @ret: void
 | 
	
		
			
				|  |  |   * @birth: created by czm in 20230327
 | 
	
	
		
			
				|  | @@ -130,9 +124,7 @@ void rabbitClient::initRecv()
 | 
	
		
			
				|  |  |      rconf = new ReadConf();
 | 
	
		
			
				|  |  |      QString path = QDir::currentPath()+"/"+RECVCONFPATH;
 | 
	
		
			
				|  |  |      ReadConf rconf_;
 | 
	
		
			
				|  |  | -    //cout<<path.toStdString()<<endl;
 | 
	
		
			
				|  |  |      rconf->Read_Conf(path.toStdString(),rconf_);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      objRabbitmq = new CRabbitMqClient(rconf_.host,
 | 
	
		
			
				|  |  |                                        rconf_.port,
 | 
	
		
			
				|  |  |                                        rconf_.userName,
 | 
	
	
		
			
				|  | @@ -146,7 +138,7 @@ void rabbitClient::initRecv()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  | - * @brief: init sendClient
 | 
	
		
			
				|  |  | + * @brief: init sendClient(初始化发送客户机)
 | 
	
		
			
				|  |  |   * @param: void
 | 
	
		
			
				|  |  |   * @ret: void
 | 
	
		
			
				|  |  |   * @birth: created by czm in 20230327
 | 
	
	
		
			
				|  | @@ -155,11 +147,8 @@ void rabbitClient::initSend()
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      rconf = new ReadConf();
 | 
	
		
			
				|  |  |      QString path = QDir::currentPath()+"/"+SENDCONFPATH;
 | 
	
		
			
				|  |  | -    //printf("path: %s\n", path.toStdString().c_str());
 | 
	
		
			
				|  |  |      ReadConf rconf_;
 | 
	
		
			
				|  |  |      rconf->Read_Conf(path.toStdString(),rconf_);
 | 
	
		
			
				|  |  | -    //std::cout<<"host :"<<rconf_.host<<" port:"<<rconf_.port<<" usr name:"<<rconf_.userName<<" psword:"<<rconf_.password<<" channel_id:"<<rconf_.channel_id<<" queue_name:"<<rconf_.queue_name<<" exchange_name:"<<rconf_.exchange_name<<" keys_name:"<<rconf_.keys_name<<std::endl;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      objRabbitmq = new CRabbitMqClient(rconf_.host,
 | 
	
		
			
				|  |  |                                        rconf_.port,
 | 
	
		
			
				|  |  |                                        rconf_.userName,
 | 
	
	
		
			
				|  | @@ -173,7 +162,7 @@ void rabbitClient::initSend()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  | - * @brief: disconnect Client
 | 
	
		
			
				|  |  | + * @brief: disconnect Client(断开连接)
 | 
	
		
			
				|  |  |   * @param: void
 | 
	
		
			
				|  |  |   * @ret: int 0-success other-fail
 | 
	
		
			
				|  |  |   * @birth: created by czm in 20230327
 | 
	
	
		
			
				|  | @@ -185,7 +174,7 @@ int rabbitClient::disConnect()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  | - * @brief: connect recv Client
 | 
	
		
			
				|  |  | + * @brief: connect recv Client(接收客户机连接)
 | 
	
		
			
				|  |  |   * @param: void
 | 
	
		
			
				|  |  |   * @ret: int 0-success other-fail
 | 
	
		
			
				|  |  |   * @birth: created by czm in 20230327
 | 
	
	
		
			
				|  | @@ -195,126 +184,78 @@ void rabbitClient::recv_connect()
 | 
	
		
			
				|  |  |      int iRet = objRabbitmq->Connect(ErrorReturn);
 | 
	
		
			
				|  |  |      if(iRet != 0){
 | 
	
		
			
				|  |  |          connection_state = false;
 | 
	
		
			
				|  |  | -        emit restart_recv_client_signal();
 | 
	
		
			
				|  |  | +        emit restart_recv_client_signal();//信号
 | 
	
		
			
				|  |  |          cout<<iRet<<endl;
 | 
	
		
			
				|  |  |          cout<<"Recv Rabbitmq Connect : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  |          return;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      connection_state = true;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    CExchange my_exchange(objRabbitmq->exchange_name);
 | 
	
		
			
				|  |  | -    iRet = objRabbitmq->DeclareExchange(my_exchange,
 | 
	
		
			
				|  |  | -                                        ErrorReturn);
 | 
	
		
			
				|  |  | -    if(iRet!=0){
 | 
	
		
			
				|  |  | -        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | -        cout<<"Recv Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    CQueue my_Queue(objRabbitmq->queue_name);
 | 
	
		
			
				|  |  | -    iRet = objRabbitmq->DeclareQueue(my_Queue,
 | 
	
		
			
				|  |  | -                                     ErrorReturn);
 | 
	
		
			
				|  |  | -    if(iRet!=0){
 | 
	
		
			
				|  |  | -        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | -        cout<<"Recv Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange,
 | 
	
		
			
				|  |  | -                                            objRabbitmq->routing_keys_name,
 | 
	
		
			
				|  |  | -                                            ErrorReturn);
 | 
	
		
			
				|  |  | -    if(iRet!=0){
 | 
	
		
			
				|  |  | -        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | -        cout<<"Recv Rabbitmq QueueBind : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +//    CExchange my_exchange(objRabbitmq->exchange_name);
 | 
	
		
			
				|  |  | +//    iRet = objRabbitmq->DeclareExchange(my_exchange,
 | 
	
		
			
				|  |  | +//                                        ErrorReturn);
 | 
	
		
			
				|  |  | +//    if(iRet!=0){
 | 
	
		
			
				|  |  | +//        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | +//        cout<<"Recv Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//    CQueue my_Queue(objRabbitmq->queue_name);
 | 
	
		
			
				|  |  | +//    iRet = objRabbitmq->DeclareQueue(my_Queue,
 | 
	
		
			
				|  |  | +//                                     ErrorReturn);
 | 
	
		
			
				|  |  | +//    if(iRet!=0){
 | 
	
		
			
				|  |  | +//        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | +//        cout<<"Recv Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange,
 | 
	
		
			
				|  |  | +//                                            objRabbitmq->routing_keys_name,
 | 
	
		
			
				|  |  | +//                                            ErrorReturn);
 | 
	
		
			
				|  |  | +//    if(iRet!=0){
 | 
	
		
			
				|  |  | +//        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | +//        cout<<"Recv Rabbitmq QueueBind : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  |      disconnect_index =0;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  | - * @brief: connect send Client
 | 
	
		
			
				|  |  | + * @brief: connect send Client(连接发送客户机)
 | 
	
		
			
				|  |  |   * @param: void
 | 
	
		
			
				|  |  |   * @ret: int 0-success other-fail
 | 
	
		
			
				|  |  |   * @birth: created by czm in 20230327
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  void rabbitClient::send_connect()
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    //std::cout<<"host :"<<rconf_.host<<" port: "<<rconf_.port<<" usr name:"<<rconf_.userName<<" psword: "<<rconf_.password<<" channel_id: "<<rconf_.channel_id<<" queue_name: "<<rconf_.queue_name<<" exchange_name: "<<rconf_.exchange_name<<" keys_name: "<<rconf_.keys_name<<std::endl;
 | 
	
		
			
				|  |  |      int iRet = objRabbitmq->Connect(ErrorReturn);
 | 
	
		
			
				|  |  |      if(iRet != 0){
 | 
	
		
			
				|  |  |          connection_state = false;
 | 
	
		
			
				|  |  | -        emit restart_send_client_signal();
 | 
	
		
			
				|  |  | +        emit restart_send_client_signal();//信号
 | 
	
		
			
				|  |  |          cout<<iRet<<endl;
 | 
	
		
			
				|  |  |          cout<<"Send Rabbitmq Connect : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  |          return;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      connection_state = true;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    CExchange my_exchange(objRabbitmq->exchange_name);
 | 
	
		
			
				|  |  | -    iRet = objRabbitmq->DeclareExchange(my_exchange,ErrorReturn);
 | 
	
		
			
				|  |  | -    if(iRet!=0){
 | 
	
		
			
				|  |  | -        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | -        cout<<"Send Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    CQueue my_Queue(objRabbitmq->queue_name);
 | 
	
		
			
				|  |  | -    iRet = objRabbitmq->DeclareQueue(my_Queue, ErrorReturn);
 | 
	
		
			
				|  |  | -    if(iRet!=0){
 | 
	
		
			
				|  |  | -        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | -        cout<<"Send Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange, objRabbitmq->routing_keys_name, ErrorReturn);
 | 
	
		
			
				|  |  | -    if(iRet!=0){
 | 
	
		
			
				|  |  | -        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | -        cout<<"Send Rabbitmq QueueBind : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +//    CExchange my_exchange(objRabbitmq->exchange_name);
 | 
	
		
			
				|  |  | +//    iRet = objRabbitmq->DeclareExchange(my_exchange,ErrorReturn);
 | 
	
		
			
				|  |  | +//    if(iRet!=0){
 | 
	
		
			
				|  |  | +//        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | +//        cout<<"Send Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//    CQueue my_Queue(objRabbitmq->queue_name);
 | 
	
		
			
				|  |  | +//    iRet = objRabbitmq->DeclareQueue(my_Queue, ErrorReturn);
 | 
	
		
			
				|  |  | +//    if(iRet!=0){
 | 
	
		
			
				|  |  | +//        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | +//        cout<<"Send Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange, objRabbitmq->routing_keys_name, ErrorReturn);
 | 
	
		
			
				|  |  | +//    if(iRet!=0){
 | 
	
		
			
				|  |  | +//        cout<<iRet<<endl;
 | 
	
		
			
				|  |  | +//        cout<<"Send Rabbitmq QueueBind : "<<ErrorReturn<<endl;
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  |      disconnect_index = 0;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -/*
 | 
	
		
			
				|  |  | - * @brief: read img by binary and change to base64
 | 
	
		
			
				|  |  | - * @param: img path
 | 
	
		
			
				|  |  | - * @ret: Base64 encoded image information
 | 
	
		
			
				|  |  | - * @birth: created by czm in 20230404
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -string rabbitClient::readImg(string img_path)
 | 
	
		
			
				|  |  | -{
 | 
	
		
			
				|  |  | -    //    printf("-----------read img start-----------------\n");
 | 
	
		
			
				|  |  | -    //    //用来存储读取出来的字节数据
 | 
	
		
			
				|  |  | -    //    std::string img_data_str;
 | 
	
		
			
				|  |  | -    //    ifstream i_f_stream(img, ifstream::binary);
 | 
	
		
			
				|  |  | -    //    i_f_stream.seekg(0, i_f_stream.end);
 | 
	
		
			
				|  |  | -    //    int length = i_f_stream.tellg();
 | 
	
		
			
				|  |  | -    //    i_f_stream.seekg(0, i_f_stream.beg);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    //    char *buffer = new char[length];
 | 
	
		
			
				|  |  | -    //    i_f_stream.read(buffer, length);
 | 
	
		
			
				|  |  | -    //    i_f_stream.close();
 | 
	
		
			
				|  |  | -    //    // 将img_data的img_size个数据赋值给img_data_str
 | 
	
		
			
				|  |  | -    //    img_data_str.assign(buffer, length);
 | 
	
		
			
				|  |  | -    //    // 防止内存泄露
 | 
	
		
			
				|  |  | -    //    delete buffer;
 | 
	
		
			
				|  |  | -    QImage *img = new QImage;
 | 
	
		
			
				|  |  | -    if( !(img->load(QString::fromStdString(img_path))) )   //如果图片不存在
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        delete img;
 | 
	
		
			
				|  |  | -        return "";
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    QFileInfo imageInfo = QFileInfo(QString::fromStdString(img_path));
 | 
	
		
			
				|  |  | -    QString sImgSuffix = imageInfo.suffix(); //获取图片文件后缀
 | 
	
		
			
				|  |  | -    QByteArray baImgSuffix = sImgSuffix.toLatin1(); //将后缀QString转char *
 | 
	
		
			
				|  |  | -    QByteArray baImgData; //保存图片数据的字符数组
 | 
	
		
			
				|  |  | -    QBuffer buf(&baImgData);  //将字符数组与buffer缓存区绑定,以便写入数据
 | 
	
		
			
				|  |  | -    //原型为 img->save(&buf, "jpg"),将图片以JPG格式写入buffer; 但有时候所选图片后缀为其他格式,为避免错误,选择用获取图片后缀方式填写,类型为char*
 | 
	
		
			
				|  |  | -    img->save(&buf, baImgSuffix.data());
 | 
	
		
			
				|  |  | -    QByteArray baImgToHexed = baImgData.toBase64(); //因为缓存已与baImgData绑定,故缓存的数据也绑定在baImgData中
 | 
	
		
			
				|  |  | -    buf.close();
 | 
	
		
			
				|  |  | -    QString sImgB64Data(baImgToHexed); //将Base64转QString
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -       ofstream outfile("img.txt",ios::app);
 | 
	
		
			
				|  |  | -       outfile<<sImgB64Data.toStdString()<<endl;
 | 
	
		
			
				|  |  | -        outfile.close();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    return sImgB64Data.toStdString();
 | 
	
		
			
				|  |  | -}
 |