00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <cstdlib>
00009 #include "ComPlusPlus/ComPlusPlus"
00010
00011 int main ( int argc, char *argv [] ) {
00012
00013 if ( argc != 2 ) {
00014 std::cout << "Usage: " << argv [0] << "port \n";
00015 exit(1);
00016 }
00017
00018 int CPort = std::atoi ( argv[1] );
00019 int port=0;
00020 std::string host="";
00021
00022 try {
00023 int SPort = CPort + 1;
00024 compp::SocketUdp Srv( SPort );
00025 char buf[1000];
00026 std::memset( (void*)buf, 0, sizeof ( buf ) );
00027 compp::SocketUdp Clnt(CPort);
00028
00029
00030 Clnt.Sendto("Hello Udp1!", 11, "127.0.0.1", SPort);
00031 Srv.Recv(buf, sizeof(buf),0);
00032 std::cout << "---" << buf << "---\n";
00033
00034
00035 Clnt.Sendto("Hello Udp1.1!", 13, "127.0.0.1", SPort);
00036 Srv.Read(buf, sizeof(buf), host, port);
00037 std::cout << "---" << buf << "sender host " << host << " sender port " << port << "---\n";
00038
00039
00040
00041 std::memset( (void*)buf, 0, sizeof ( buf ) );
00042 Clnt.Sendto("Hello Udp2!", 11, "127.0.0.1", SPort);
00043 Srv.Connect("127.0.0.1", CPort);
00044 Srv.Read(buf, sizeof(buf), host, port);
00045 std::cout << "---" << buf << "sender host " << host << " sender port " << port << "---\n";
00046
00047
00048 std::memset( (void*)buf, 0, sizeof ( buf ) );
00049 Srv.Send("Hello Udp3!", 11,0);
00050 Clnt.Recv((void*)buf, 11,0);
00051
00052 std::cout << "---" << buf << "---\n";
00053
00054
00055 std::memset( (void*)buf, 0, sizeof ( buf ) );
00056 Clnt.Connect("127.0.0.1", SPort);
00057 Srv.Write("Hello Udp4!");
00058 Clnt.Read(buf, 11, host, port);
00059 std::cout << "---" << buf << "sender host " << host << " sender port " << port << "---\n";
00060
00061 return 0;
00062 } catch ( syspp::ComException e ) {
00063 std::cout << "Exception " << e.what( ) << "\n" ;
00064 }
00065 }