Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here’s why you should **you** care about ZeroMQ.
- ---
- Connecting as a Server:
- QString ip_address = QString("tcp://") + ui->addressEdit->text();
- should be
- QString ip_address = QString("tcp://") + ui->addressEdit->text();
- ---
- Connecting as a client -- add space to align comment
- ---
- Message loop
- void MainWindow::msgLoop()
- {
- char buffer[20];
- int res = zmq_recv(socket, buffer, 19, ZMQ_DONTWAIT); // Don’t hang up here, don’t wait
- if (res > 0 ) {
- if ( isClient ) {
- ui->sendEdit_2->setText(QString(buffer)); // Show reply - only for Request side
- } else {
- ui->sendEdit->setText(QString(buffer)); // Show request
- buffer[0] = 'A';
- buffer[1] = 'B';
- zmq_send(socket, buffer, 19, 0) ; // fix up the message and send it back
- }
- }
- QTimer::singleShot(5000, this, &MainWindow::msgLoop); // Repeat
- }
- Should be:
- void MainWindow::msgLoop()
- {
- char buffer[20];
- int res = zmq_recv(socket, buffer, 19, ZMQ_DONTWAIT); // Don’t hang up here, don’t wait
- if (res > 0 ) {
- if ( isClient ) {
- ui->sendEdit_2->setText(QString(buffer)); // Show reply - only for Request side
- } else {
- ui->sendEdit->setText(QString(buffer)); // Show request
- buffer[0] = 'A';
- buffer[1] = 'B';
- zmq_send(socket, buffer, 19, 0) ; // fix up the message and send it back
- }
- }
- QTimer::singleShot(5000, this, &MainWindow::msgLoop); // Repeat
- }
- In addition, I'd like to add that it will be great to avoid all unnamed constants.
- const int BUFFER_SIZE = 20;
- const int LOOP_FREQ = 5000; // in ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement