00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <string>
00009 #include <cstdlib>
00010 #include "ComPlusPlus/ComPlusPlus"
00011
00012 int main (int argc, char *argv [] ) {
00013
00014 std::string str,FNC = "/tmp/Client";
00015 std::string FNS = "/tmp/Server";
00016 std::string string2besent= "Hello World";
00017 std::string string2bereceived;
00018
00019 try {
00020 std::cout << "Unix Socket Test: Stream Mode\n";
00021
00022 compp::SocketUnix Client (FNC, compp::STREAM);
00023
00024 compp::SocketUnix *S, Server (FNS, compp::STREAM);
00025
00026 Server.Listen();
00027 Client.Connect ( FNS );
00028 S = Server.Accept ();
00029 Client.SetReadAhead ( true );
00030 S->SetReadAhead ( true );
00031
00032 Client.Write ( "1234567890" );
00033 S->Read ( str, 5 ) ;
00034 std::cout << "1. received " << str << "\n";
00035
00036 Client.Write ( "ABCDEFGH" ) ;
00037 S->Read ( str, 5 ) ;
00038 std::cout << "2. received " << str << "\n";
00039
00040 S->Read ( str, 8 ) ;
00041 std::cout << "3. received " << str << "\n";
00042
00043 } catch ( syspp::ComException e ) {
00044 std::cout << "Exception " << e.what() << "\n" ;
00045 }
00046
00047
00048 try {
00049 std::string from;
00050 char c [65536];
00051 memset ( c, 0, sizeof ( c ));
00052 FNC="DGRAMC";
00053 FNS="DGRAMS";
00054 std::cout << "Unix Socket Test: Datagram Mode\n";
00055
00056 compp::SocketUnix Client (FNC, compp::DATAGRAM);
00057
00058 compp::SocketUnix Server (FNS, compp::DATAGRAM);
00059
00060 Client.Sendto ( "Hello", 5, FNS );
00061 Server.Recvfrom ( c, 65536, 0, from );
00062
00063 std::cout << "Unix Socket Test: received string " << c << "from " << from << "\n";
00064
00065 } catch ( syspp::ComException e ) {
00066 std::cout << "Exception " << e.what() << "\n" ;
00067 }
00068
00069 return 0;
00070 }
00071