Advertisement
troyan3

ZMQ in ICS

Jun 30th, 2018
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Here’s why you should **you** care about ZeroMQ.
  3. ---
  4. Connecting as a Server:
  5.  
  6. QString ip_address = QString("tcp://") + ui->addressEdit->text();
  7.  
  8. should be
  9.  
  10. QString ip_address = QString("tcp://") + ui->addressEdit->text();
  11. ---
  12. Connecting as a client -- add space to align comment
  13. ---
  14. Message loop
  15.  
  16. void MainWindow::msgLoop()
  17. {
  18. char buffer[20];
  19. int res = zmq_recv(socket, buffer, 19, ZMQ_DONTWAIT); // Don’t hang up here, don’t wait
  20. if (res > 0 ) {
  21. if ( isClient ) {
  22. ui->sendEdit_2->setText(QString(buffer));  // Show reply - only for Request side
  23. } else {
  24. ui->sendEdit->setText(QString(buffer));   // Show request
  25. buffer[0] = 'A';
  26. buffer[1] = 'B';
  27. zmq_send(socket, buffer, 19, 0) ;  // fix up the message and send it back
  28. }
  29. }
  30. QTimer::singleShot(5000, this, &MainWindow::msgLoop);  // Repeat
  31. }
  32.  
  33.  
  34. Should be:
  35.  
  36.         void MainWindow::msgLoop()
  37.         {
  38.             char buffer[20];
  39.             int res = zmq_recv(socket, buffer, 19, ZMQ_DONTWAIT); // Don’t hang up here, don’t wait
  40.             if (res > 0 ) {
  41.                 if ( isClient ) {
  42.                     ui->sendEdit_2->setText(QString(buffer));  // Show reply - only for Request side
  43.                 } else {
  44.                     ui->sendEdit->setText(QString(buffer));   // Show request
  45.                     buffer[0] = 'A';
  46.                     buffer[1] = 'B';
  47.                     zmq_send(socket, buffer, 19, 0) ;  // fix up the message and send it back
  48.                 }
  49.             }
  50.             QTimer::singleShot(5000, this, &MainWindow::msgLoop);  // Repeat
  51.         }
  52.  
  53. In addition, I'd like to add that it will be great to avoid all unnamed constants.
  54.  
  55. const int BUFFER_SIZE = 20;
  56. const int LOOP_FREQ = 5000; // in ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement