Monday, December 21, 2009

Boost Message Queue (Interprocess) Sender

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// InterProcess Message Queue with Boost::interprocess
// Message Queue Sender
// Date : 26 - Nov -2009
// Author: Prakhar Dubey (prakharprakhar@gmail.com)
// Compile: g++ mq_sender.cpp -o mq_sender -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;

// Any structure to be send to message queue
typedef struct s_Request{
int src_ip,des_ip;
boost::asio::ip::address clientAddress;
char name[50];
}st_Request;

int main ()
{
try{
//Create data to be entered
st_Request data1 = {10,20,boost::asio::ip::address::from_string("10.31.141.45"),"www.google.com"};

st_Request data2 = {40,50,boost::asio::ip::address::from_string("192.168.64.152") ,"www.rediff.com"};



//Erase previous message queue
message_queue::remove("message_queue");
//Create a message_queue.
message_queue mq
(create_only //only create
,"message_queue" //name
,100 //max message number
,sizeof(st_Request) //max message size
);

//Send 100 numbers
//for(int i = 0; i < 100; ++i){
// mq.send(&i, sizeof(i), 0);
//}

//Send 2 structures
mq.send(&data1, sizeof(st_Request), 0);
mq.send(&data2, sizeof(st_Request), 0);
}
catch(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
}
return 0;
}

1 comment:

  1. Positive site, where did u produce the data on 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