void ZMQActor::readTasks() { while(_isReading) { ZMQMessage message; ZMQSocket::Error error; std::string id; std::string address; if (_actor.receive(message, error)) { if (message.data() == "ZMQActor::stopPerformingTasks") { break; } if (_taskCallBack) if (!_taskCallBack(message)) break; } else { break; } } ZMQ_LOG_INFO("ZMQActor::readTasks ENDED"); _isReading = false; }
int main(int argc, char **argv) { if ( argc < 2 ) { printf("usage: %s <bind string>\n", argv[0]); return EXIT_FAILURE; } try { wxString connectAddress(argv[1], wxConvUTF8); ZMQContext context; ZMQSocket s(context, ZMQSocket::Reply); // Server socket type s.bind( connectAddress ); // wait for messages s.setTimeout( 1000 ); while ( true ) { ZMQMessage incMessage; if ( s.recvMessage( incMessage ) ) { wxPrintf(wxT("Received message: %s\n"), incMessage.GetString().c_str()); // Message received! // process it wxString reply( incMessage.GetString() ); reply << wxT(" - a reply!"); s.sendMessage( reply ); } } } catch (ZMQException &e) { wxPrintf(wxT("error: %s\n"), e.What().c_str()); } return 0; }
NZMQT_INLINE QList<QByteArray> ZMQSocket::receiveMessage(ReceiveFlags flags_) { QList<QByteArray> parts; ZMQMessage msg; while (receiveMessage(&msg, flags_)) { parts += msg.toByteArray(); msg.rebuild(); if (!hasMoreMessageParts()) break; } return parts; }
// Receives a message. // The message is represented as a list of byte arrays representing // a message's parts. If the message is not a multi-part message the // list will only contain one array. inline QList<QByteArray> receiveMessage() { QList<QByteArray> parts; ZMQMessage msg; while (receiveMessage(&msg)) { parts += msg.toByteArray(); msg.rebuild(); if (!hasMoreMessageParts()) break; } return parts; }
bool rx(ZMQSubscribeSocket &socket) { ZMQMessage msg; if (msg.recv(socket) == 0) return false; ZMQServoMessage *data = (ZMQServoMessage *)msg.data(); Servos::iterator j = servos.find(data->servoId); if (j != servos.end()) { switch(data->messageId) { case ZMQServoMessage::GET_ANGLE: j->second->presentAngle=data->value; break; case ZMQServoMessage::GET_TEMP: j->second->temp(data->value); break; } } return true; }
bool handleEvent(ZMQMessage& message) { ZMQMessage::Headers headers; message.parseHeaders(headers); //ZMQ_LOG_DEBUG(headers.address << "-" << headers.identifier << "-" << headers.body << "-" << pthread_self()); exitNotifier = headers.identifier == "call.bye"; return true; }
bool ZMQActor::readReactorTasks(const std::string& id, const std::string& address, ZMQMessage& message) { std::ostringstream task; task << id << " " << address << " " << message.data(); ZMQMessage reactorMessage(task.str()); putTask(reactorMessage); return true; }