00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00018 #include <iostream>
00019 #include <string>
00020
00021 #include <Channel.h>
00022
00023 using namespace std;
00024 using namespace channel;
00025
00026
00027
00028
00029 typedef StringPathId<'/'> IdType;
00030
00031 typedef Channel<IdType, IdTrait<IdType>, ACE_MT_SYNCH, TrieRouter<IdType, IdTrait<IdType>, ACE_MT_SYNCH> > Chan;
00032 typedef Chan::Msg ChanMsg;
00033
00034
00035
00036
00037
00038 const char * PING_MSG = "/APP/PING";
00039 const char * PONG_MSG = "/APP/PONG";
00040 const char * TEST_STRING_MSG = "/APP/TEST";
00041 const char * APP_WILDCARD_MSG = "/APP/*";
00042
00043 struct Test_String_Msg {
00044 enum { MAX_STR_LEN = 1024 };
00045 int len;
00046 char data[MAX_STR_LEN];
00047 Test_String_Msg() {
00048 }
00049 };
00050
00051
00052
00053
00054
00055 int main (int argc, char **argv) {
00056 if (argc < 2) {
00057 std::cout << "Usage: hsend peer_host:port\n";
00058 return -1;
00059 }
00060
00061
00062 Chan * my_chan = new Chan();
00063
00064
00065 char *peer_addr = argv[1];
00066 Chan::TcpSockConnector *tcp_conn = new Chan::TcpSockConnector(my_chan, true);
00067 tcp_conn->open ();
00068 ConnInfo ci(peer_addr);
00069 if (tcp_conn->connect (ci) == FAILURE) {
00070 cout << "failed to connect peer tcp socket at " << peer_addr << endl;
00071 return -1;
00072 }
00073
00074
00075 Chan::Source my_src(my_chan);
00076
00077
00078 my_src.publish_msg(APP_WILDCARD_MSG);
00079
00080 cout << "hier_sender coming up ...\n";
00081
00082
00083 for(;;) {
00084 cout << "--- Please enter one line msg [type(ping,pong,test)|data] ";
00085 Test_String_Msg *tm = new Test_String_Msg();
00086 if (!gets (tm->data))
00087 break;
00088 tm->len = strlen(tm->data)+1;
00089 string str(tm->data);
00090 size_t pos = str.find('|');
00091 const char *id;
00092 if (pos == string::npos)
00093 id = TEST_STRING_MSG;
00094 else if (str.substr(0,pos) == "ping")
00095 id = PING_MSG;
00096 else if (str.substr(0,pos) == "pong")
00097 id = PONG_MSG;
00098 else
00099 id = TEST_STRING_MSG;
00100
00101 my_src.send_msg (id, tm);
00102 }
00103
00104 cout << "hier_sender exits...\n";
00105
00106 return 0;
00107 }