//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// InterProcess Message Queue with Boost::interprocess
// Message Queue Receiver
// Date : 26 - Nov -2009
// Author: Prakhar Dubey (prakharprakhar@gmail.com)
// Compile: g++ mq_receiver.cpp -o mq_receiver -I path_to_boost -lboost_system-gcc43-mt-1_39
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include <boost/interprocess/ipc/message_queue.hpp>
#include <iostream>
#include <vector>
#include <boost/asio.hpp>
using namespace boost::interprocess;
// Structure to be read
typedef struct s_Request{
int src_ip,des_ip;
boost::asio::ip::address objRequest;
char name[50];
}st_Request;
int main ()
{
try{
//Open a message queue.
message_queue mq
(open_only //only create
,"message_queue" //name
);
unsigned int priority;
std::size_t recvd_size;
//Receive 100 numbers
/*for(int i = 0; i < 100; ++i){
int number;
mq.receive(&number, sizeof(number), recvd_size, priority);
if(number != i || recvd_size != sizeof(number))
return 1;
else
std::cout << "nnumber = " << number;
}*/
//Receive Structure
st_Request dataone, datatwo;
mq.receive(&dataone, sizeof(st_Request), recvd_size, priority);
if(recvd_size != sizeof(st_Request))
return 1;
else{
std::cout << "nsrcip = " << dataone.src_ip;
std::cout << "ndesip = " << dataone.des_ip;
std::cout << "nRequest = " << dataone.objRequest.to_string();
std::cout << "nname = " << dataone.name;
}
}
catch(interprocess_exception &ex){
message_queue::remove("message_queue");
std::cout << ex.what() << std::endl;
return 1;
}
message_queue::remove("message_queue");
return 0;
}
Positive site, where did u develop the info with this posting? I'm pleased I discovered it though, ill be checking back soon to discover what additional posts you include.duo queue boost
ReplyDelete