head 1.3; access; symbols; locks; strict; comment @# @; 1.3 date 2002.09.07.01.50.41; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.19.01.58; author curt; state Exp; branches; next 1.1; 1.1 date 2002.08.31.18.54.05; author curt; state Exp; branches; next ; desc @@ 1.3 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# tcp_client.cxx

    00001 #include <simgear/compiler.h>
    00002 #include STL_IOSTREAM
    00003
    00004 #ifdef _WIN32
    00005 #include <windows.h>
    00006 #else
    00007 #include <unistd.h>
    00008 #endif
    00009
    00010 #include <simgear/debug/logstream.hxx>
    00011
    00012 #include "sg_socket.hxx"
    00013
    00014 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
    00015 using std::cout;
    00016 #endif
    00017
    00018 class TcpClient
    00019 {
    00020 public:
    00021     TcpClient( const char* host, const char* port );
    00022     ~TcpClient();
    00023
    00024     bool open();
    00025     bool process();
    00026     bool close();
    00027
    00028 private:
    00029     SGIOChannel* channel;
    00030 };
    00031
    00032 TcpClient::TcpClient( const char* host, const char* port )
    00033 {
    00034     channel = new SGSocket( host, port, "tcp" );
    00035 }
    00036
    00037 TcpClient::~TcpClient()
    00038 {
    00039     delete channel;
    00040 }
    00041
    00042 bool
    00043 TcpClient::open()
    00044 {
    00045     return channel->open( SG_IO_OUT );
    00046 }
    00047
    00048 bool
    00049 TcpClient::process()
    00050 {
    00051     char wbuf[1024];
    00052
    00053     sprintf( wbuf, "hello world\n" );
    00054     int length = channel->writestring( wbuf );
    00055     cout << "writestring returned " << length << "\n";
    00056
    00057     return true;
    00058 }
    00059
    00060 bool
    00061 TcpClient::close()
    00062 {
    00063     return channel->close();
    00064 }
    00065
    00066 int
    00067 main()
    00068 {
    00069     sglog().setLogLevels( SG_ALL, SG_INFO );
    00070     TcpClient client( "localhost", "5500" );
    00071     if (!client.open())
    00072     {
    00073         cout << "client open failed\n";
    00074         return 0;
    00075     }
    00076
    00077     for (int i = 0; i < 3; ++i)
    00078     {
    00079         client.process();
    00080 #ifdef _WIN32
    00081         Sleep(1000);
    00082 #else
    00083         sleep(1);
    00084 #endif
    00085     }
    00086
    00087     //client.close();
    00088     return 0;
    00089 }

@ 1.2 log @Oops, try again. @ text @d11 28 a38 28 00003 #include <unistd.h> 00004 00005 #include <simgear/debug/logstream.hxx> 00006 00007 #include "sg_socket.hxx" 00008 00009 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS 00010 using std::cout; 00011 #endif 00012 00013 class TcpClient 00014 { 00015 public: 00016 TcpClient( const char* host, const char* port ); 00017 ~TcpClient(); 00018 00019 bool open(); 00020 bool process(); 00021 bool close(); 00022 00023 private: 00024 SGIOChannel* channel; 00025 }; 00026 00027 TcpClient::TcpClient( const char* host, const char* port ) 00028 { 00029 channel = new SGSocket( host, port, "tcp" ); 00030 } d40 1 a40 1 00032 TcpClient::~TcpClient() d42 1 a42 1 00034 delete channel; d45 10 a54 10 00037 bool 00038 TcpClient::open() 00039 { 00040 return channel->open( SG_IO_OUT ); 00041 } 00042 00043 bool 00044 TcpClient::process() 00045 { 00046 char wbuf[1024]; d56 43 a98 34 00048 sprintf( wbuf, "hello world\n" ); 00049 int length = channel->writestring( wbuf ); 00050 cout << "writestring returned " << length << "\n"; 00051 00052 return true; 00053 } 00054 00055 bool 00056 TcpClient::close() 00057 { 00058 return channel->close(); 00059 } 00060 00061 int 00062 main() 00063 { 00064 sglog().setLogLevels( SG_ALL, SG_INFO ); 00065 TcpClient client( "localhost", "5500" ); 00066 if (!client.open()) 00067 { 00068 cout << "client open failed\n"; 00069 return 0; 00070 } 00071 00072 for (int i = 0; i < 3; ++i) 00073 { 00074 client.process(); 00075 sleep(1); 00076 } 00077 00078 //client.close(); 00079 return 0; 00080 }