///////////////////////////////////////////////////////////////////////// // Client.cpp - Tests asynchronous message-passing IPC using // // ver 1.1 // // Language: Visual C++ 2008 // // Platform: Dell Precision T7400, Vista Ultimate, SP1 // // Application: Help for CSE687 - Object Oriented Design, Project #2 // // Author: Jim Fawcett, CST 4-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////////// /* * Module Operations: * ================== * Test asynchronous message-passing using the MessageMgr and MMFmgr * modules. * * Note: * Client should call MsgMgr::wait() to wait for server to come up * before sending or waiting for messages. * * Required Files: * Client.cpp, Server.cpp, MessageMgr.h, MessageMgr.cpp, MMFmgr.h, MMFmgr.cpp, * Threads.h, Threads.cpp, BlockingQueue.h, locks.h * * Build Command: * cl /EHa Client.cpp MessageMgr.cpp MMFmgr.cpp Threads.cpp * cl /EHa Server.cpp MessageMgr.cpp MMFmgr.cpp Threads.cpp * * Maintenance History: * ver 1.1 : 26 Mar 09 * - removed debugString references and some no longer needed includes. * - fixed a problem with project references to threads and locks modules * ver 1.0 : 22 Mar 09 * - first release */ #include "..\MessageMgr\MessageMgr.h" #include #include #include template std::string ToString(T t) { std::ostringstream out; out << t; return out.str(); } void main() { sout << "\n Client using Message-Passing IPC facility"; sout << "\n ===========================================\n"; try { MsgMgr client(MMFmgr::client); client.wait(); sout << "\n server started"; std::string msg = "1st"; sout << locker << "\n sending opening message: " << msg << unlocker; client.putMessage(msg); sout << "\n waiting for server's message"; msg = client.getMessage(); sout << locker << "\n message is: " << msg.c_str() << "\n" << unlocker; msg = ""; for(int i=0; i<20; ++i) { std::string msg = "msg#" + ToString(i) + " - a not very interesting message"; client.putMessage(msg); sout << "\n sending message: " << msg.c_str(); } client.putMessage("quit"); sout << "\n\n"; sout << "\n Press enter to quit"; std::cin.get(); } catch(std::exception& ex) { sout << ex.what(); } }