00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <cstdlib>
00009 #include <string>
00010 #include "ComPlusPlus/ComPlusPlus"
00011
00012 int main (int argc, char *argv [] ) {
00013
00014 if ( argc < 2 ) {
00015 std::cout << "Usage " << argv[0] << " port [bind-addr]\n";
00016 return 1;
00017 }
00018
00019 int port = std::atoi(argv [1]) ;
00020
00021 std::string host = "0";
00022
00023 if ( argc == 3 ) {
00024 host = argv [ 2 ];
00025 }
00026
00027 try {
00028
00029 compp::SocketUdp Receiver;
00030 Receiver.SetSockOptBroadcast ( true );
00031 Receiver.SetSockOptReuseAddress ( true );
00032 Receiver.Bind(host, port);
00033
00034 do {
00035 int i;
00036 char buf[1000];
00037 std::memset((void*)buf, 0, sizeof(buf));
00038 std::string host;
00039 int port;
00040
00041 i = Receiver.Read(buf, sizeof(buf), host, port );
00042 if ( i > 0 )
00043 std::cout << buf << "\n";
00044 } while ( true) ;
00045
00046 std::cout << "Connection closed\n";
00047
00048 } catch ( syspp::ComException e ) {
00049 std::cout << "Exception " << e.what() << "\n" ;
00050 }
00051 return 0;
00052 }