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_server.cxx

    00001 #include <simgear/compiler.h>
    00002 #include <simgear/debug/logstream.hxx>
    00003 #include STL_STRING
    00004 #include STL_IOSTREAM
    00005
    00006 #include "sg_socket.hxx"
    00007
    00008 using std::string;
    00009 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
    00010 using std::cout;
    00011 #endif
    00012
    00013 class TcpServer
    00014 {
    00015 public:
    00016     TcpServer();
    00017     bool open();
    00018     bool process();
    00019     bool close();
    00020
    00021 private:
    00022     SGIOChannel* channel;
    00023 };
    00024
    00025 TcpServer::TcpServer()
    00026 {
    00027     channel = new SGSocket( "", "5500", "tcp" );
    00028 }
    00029
    00030 bool
    00031 TcpServer::open()
    00032 {
    00033     channel->open( SG_IO_BI );
    00034     return true;
    00035 }
    00036
    00037 bool
    00038 TcpServer::process()
    00039 {
    00040     char buf[1024];
    00041
    00042     int len;
    00043     while ((len = channel->readline( buf, sizeof(buf) )) > 0)
    00044     {
    00045         cout << len << ": " << buf;
    00046     }
    00047     return true;
    00048 }
    00049
    00050 bool
    00051 TcpServer::close()
    00052 {
    00053     return channel->close();
    00054 }
    00055
    00056
    00057 int
    00058 main()
    00059 {
    00060     sglog().setLogLevels( SG_ALL, SG_INFO );
    00061     TcpServer server;
    00062     server.open();
    00063     SG_LOG( SG_IO, SG_INFO, "Created TCP server" );
    00064
    00065     while (1)
    00066     {
    00067         server.process();
    00068     }
    00069
    00070     server.close();
    00071     return 0;
    00072 }

@ 1.2 log @Oops, try again. @ text @d81 1 a81 1