I've made some progress with writing up a script for nzmqt bindings, but I got so many errors that I have no idea what I'm doing wrong. Currently, what I've done is declare 3 different types of sockets 1 PUSH to send messages to the server and 2 SUB to get reply from the server.
The error message I got:
In file included from main.cpp:2:0:
socket.h:26:22: error: ‘ZMQContext’ has not been declared
socket.h:26:96: error: ISO C++ forbids declaration of ‘Ventilator’ with no type [-fpermissive]
socket.h:26:96: error: only declarations of constructors can be ‘explicit’
In file included from main.cpp:2:0:
socket.h:28:26: error: ‘ZMQContext’ has not been declared
socket.h:28:112: error: ISO C++ forbids declaration of ‘Subscriber’ with no type [-fpermissive]
socket.h:28:112: error: only declarations of constructors can be ‘explicit’
socket.h:30:23: error: ‘ZMQContext’ has not been declared
socket.h:30:109: error: ISO C++ forbids declaration of ‘Subscriber2’ with no type [-fpermissive]
socket.h:30:109: error: only declarations of constructors can be ‘explicit’
socket.h:53:5: error: ‘ZMQSocket’ does not name a type
socket.h:54:5: error: ‘ZMQSocket’ does not name a type
socket.h:55:5: error: ‘ZMQSocket’ does not name a type
In file included from main.cpp:2:0:
socket.
h: In member function ‘
int Socket
::Ventilator(int
&,
const QString
&,
QObject*)’
:socket.h:26:99: error: only constructors take member initialisers
In file included from main.cpp:2:0:
socket.h:26:155: error: class ‘Socket’ does not have any field named ‘ventilator_’
socket.h:26:168: error: expected ‘{’ at end of input
socket.h:26:168: warning: no return statement in function returning non-void [-Wreturn-type]
socket.h: At global scope:
socket.h:26:11: warning: unused parameter ‘context’ [-Wunused-parameter]
make: *** [main.o] Error 1
In file included from main.cpp:2:0:
socket.h:26:22: error: ‘ZMQContext’ has not been declared
socket.h:26:96: error: ISO C++ forbids declaration of ‘Ventilator’ with no type [-fpermissive]
socket.h:26:96: error: only declarations of constructors can be ‘explicit’
In file included from main.cpp:2:0:
socket.h:28:26: error: ‘ZMQContext’ has not been declared
socket.h:28:112: error: ISO C++ forbids declaration of ‘Subscriber’ with no type [-fpermissive]
socket.h:28:112: error: only declarations of constructors can be ‘explicit’
socket.h:30:23: error: ‘ZMQContext’ has not been declared
socket.h:30:109: error: ISO C++ forbids declaration of ‘Subscriber2’ with no type [-fpermissive]
socket.h:30:109: error: only declarations of constructors can be ‘explicit’
socket.h:53:5: error: ‘ZMQSocket’ does not name a type
socket.h:54:5: error: ‘ZMQSocket’ does not name a type
socket.h:55:5: error: ‘ZMQSocket’ does not name a type
In file included from main.cpp:2:0:
socket.h: In member function ‘int Socket::Ventilator(int&, const QString&, QObject*)’:
socket.h:26:99: error: only constructors take member initialisers
In file included from main.cpp:2:0:
socket.h:26:155: error: class ‘Socket’ does not have any field named ‘ventilator_’
socket.h:26:168: error: expected ‘{’ at end of input
socket.h:26:168: warning: no return statement in function returning non-void [-Wreturn-type]
socket.h: At global scope:
socket.h:26:11: warning: unused parameter ‘context’ [-Wunused-parameter]
make: *** [main.o] Error 1
To copy to clipboard, switch view to plain text mode
Here is my current code:
Socket.cpp
#include "socket.h"
#include <QByteArray>
#include <QList>
using namespace std;
explicit Socket
::Subscriber(ZMQContext
& context,
const QString
& address,
const QString
& topic,
QObject *parent
= 0) : super(parent)
, address_("127.0.0.1:5558"), topic_("")
, socket_(0)
{
socket_ = context.createSocket(ZMQSocket::TYP_SUB, this);
socket_->setObjectName("Subscriber.Socket.socket(SUB)");
connect(socket_, SIGNAL(recvString(const QList<QByteArray>&)), SLOT(recvString(const QList<QByteArray>&)));
}
explicit Socket
::Subscriber2(ZMQContext
& context,
const QString
& address,
const QString
& topic,
QObject *parent
= 0) : super(parent)
, address2_("127.0.0.1:5559"), topic2_("")
, socket2_(0)
{
socket2_ = context.createSocket(ZMQSocket::TYP_SUB, this);
socket2_->setObjectName("Subscriber2.Socket.socket(SUB)");
connect(socket2_, SIGNAL(recvString(const QList<QByteArray>&)), SLOT(recvString(const QList<QByteArray>&)));
}
explicit Socket
::Ventilator(ZMQContext
& context,
const QString
& ventilatorAddress,
QObject* parent
= 0) : super(parent)
, ventilatorAddress_("127.0.0.1:5557"), ventilator_(0)
{
ventilator_ = context.createSocket(ZMQSocket::TYP_PUSH, this);
ventilator_->setObjectName("Ventilator.Socket.ventilator(PUSH)");
}
void Socket::startImpl()
{
socket_->subscribeTo(topic_);
socket_->connectTo(address_);
socket2_->subscribeTo(topic2_);
socket2_->connectTo(address2_);
ventilator_->connectTo(ventilatorAddress_);
}
{
this->message = message;
}
void Socket::sendString()
{
ventilator_->sendMessage(send);
}
void Socket::recvString(const QList<QByteArray>& message)
{
qDebug() << "Subscriber> " << message;
}
#include "socket.h"
#include <QByteArray>
#include <QList>
using namespace std;
explicit Socket::Subscriber(ZMQContext& context, const QString& address, const QString& topic, QObject *parent = 0)
: super(parent)
, address_("127.0.0.1:5558"), topic_("")
, socket_(0)
{
socket_ = context.createSocket(ZMQSocket::TYP_SUB, this);
socket_->setObjectName("Subscriber.Socket.socket(SUB)");
connect(socket_, SIGNAL(recvString(const QList<QByteArray>&)), SLOT(recvString(const QList<QByteArray>&)));
}
explicit Socket::Subscriber2(ZMQContext& context, const QString& address, const QString& topic, QObject *parent = 0)
: super(parent)
, address2_("127.0.0.1:5559"), topic2_("")
, socket2_(0)
{
socket2_ = context.createSocket(ZMQSocket::TYP_SUB, this);
socket2_->setObjectName("Subscriber2.Socket.socket(SUB)");
connect(socket2_, SIGNAL(recvString(const QList<QByteArray>&)), SLOT(recvString(const QList<QByteArray>&)));
}
explicit Socket::Ventilator(ZMQContext& context, const QString& ventilatorAddress, QObject* parent = 0)
: super(parent)
, ventilatorAddress_("127.0.0.1:5557"), ventilator_(0)
{
ventilator_ = context.createSocket(ZMQSocket::TYP_PUSH, this);
ventilator_->setObjectName("Ventilator.Socket.ventilator(PUSH)");
}
void Socket::startImpl()
{
socket_->subscribeTo(topic_);
socket_->connectTo(address_);
socket2_->subscribeTo(topic2_);
socket2_->connectTo(address2_);
ventilator_->connectTo(ventilatorAddress_);
}
void Socket::send(QString message)
{
this->message = message;
}
void Socket::sendString()
{
ventilator_->sendMessage(send);
}
void Socket::recvString(const QList<QByteArray>& message)
{
qDebug() << "Subscriber> " << message;
}
To copy to clipboard, switch view to plain text mode
Socket.h
#ifndef SOCKET_H
#define SOCKET_H
#include <nzmqt/nzmqt.hpp>
#include <QByteArray>
#include <QDateTime>
#include <QList>
#include <QTimer>
#include <QThread>
namespace nzmqt
{
class Socket;
}
{
Q_OBJECT
public:
explicit Ventilator
(ZMQContext
& context,
const QString
& ventilatorAddress,
QObject* parent
= 0): QThread(parent
), ventilatorAddress_
(ventilatorAddress
), ventilator_
(0);
explicit Subscriber
(ZMQContext
& context,
const QString
& address,
const QString
& topic,
QObject *parent
= 0);
explicit Subscriber2
(ZMQContext
& context,
const QString
& address,
const QString
& topic,
QObject *parent
= 0);
signals:
void stringRecv(const QList<QByteArray>& message);
public slots:
protected:
void startImpl();
protected slots:
void recvString();
void sendString();
private:
ZMQSocket* socket_;
ZMQSocket* socket2_;
ZMQSocket* ventilator_;
};
#endif // SOCKET_H
#ifndef SOCKET_H
#define SOCKET_H
#include <nzmqt/nzmqt.hpp>
#include <QByteArray>
#include <QDateTime>
#include <QList>
#include <QTimer>
#include <QThread>
namespace nzmqt
{
class Socket;
}
class Socket : public QThread
{
Q_OBJECT
public:
explicit Ventilator(ZMQContext& context, const QString& ventilatorAddress, QObject* parent = 0): QThread(parent), ventilatorAddress_(ventilatorAddress), ventilator_(0);
explicit Subscriber(ZMQContext& context, const QString& address, const QString& topic, QObject *parent = 0);
explicit Subscriber2(ZMQContext& context, const QString& address, const QString& topic, QObject *parent = 0);
signals:
void stringRecv(const QList<QByteArray>& message);
public slots:
void sendsig(QString signal);
protected:
void startImpl();
protected slots:
void recvString();
void sendString();
private:
QString signal;
QString address_;
QString topic_;
QString address2_;
QString topic2_;
QString ventilatorAddress_;
ZMQSocket* socket_;
ZMQSocket* socket2_;
ZMQSocket* ventilator_;
};
#endif // SOCKET_H
To copy to clipboard, switch view to plain text mode
Bookmarks