notify.cc

Go to the documentation of this file.
00001 
00017 #include <string>
00018 #include <iostream>
00019 #include "unix_buffer.H"
00020 
00021 using namespace std;
00022 
00023 const int server_port = 12365;
00024 
00025 void send_notification(const string server, const string message)
00026 {
00027   // client sends message to server
00028   cout << "sending notification to " << server << endl;
00029   unix_io_stream tcp(server,server_port);
00030   cout << tcp.connection_info() << endl;
00031   tcp << message << endl;
00032   string s;
00033   tcp >> s;
00034   cout << s << endl;
00035 }
00036 
00037 void wait_for_notification()
00038 {
00039   // server waits for message from client
00040   connection_waiter my_connection_waiter(server_port);
00041   unix_io_stream tcp(my_connection_waiter); // wait for client call
00042   cout << tcp.connection_info() << endl;
00043   string s;
00044   tcp >> s;
00045   cout << "received: " << s << endl;
00046   tcp << "pong." << endl;
00047 }
00048 
00049 int main(const int argc, const char* const argv[])
00050 {
00051  if (argc==1)
00052   {
00053     // server mode
00054     wait_for_notification();
00055     exit(0);
00056   }
00057  else if (argc==2 || argc==3)
00058   {
00059     // client mode
00060     send_notification(argv[1], (argc==3) ? argv[2] : "ping.");
00061     exit(0);
00062   }
00063  else
00064   {
00065     // invalid
00066     cout << "invalid parameters!" << endl;
00067     exit(1);
00068   }
00069 }

Generated on Wed Nov 7 23:29:25 2007 for Qsieve by  doxygen 1.5.4