]> git.mxchange.org Git - simgear.git/blob - simgear/io/tcp_server.cxx
Tidy up the autoconf/automake configuration a bit.
[simgear.git] / simgear / io / tcp_server.cxx
1 #include <simgear/compiler.h>
2 #include <simgear/debug/logstream.hxx>
3 #include STL_STRING
4 #include STL_IOSTREAM
5
6 #include "sg_socket.hxx"
7
8 using std::string;
9 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
10 using std::cout;
11 #endif
12
13 class TcpServer
14 {
15 public:
16     TcpServer();
17     bool open();
18     bool process();
19     bool close();
20
21 private:
22     SGIOChannel* channel;
23 };
24
25 TcpServer::TcpServer()
26 {
27     channel = new SGSocket( "", "5500", "tcp" );
28 }
29
30 bool
31 TcpServer::open()
32 {
33     channel->open( SG_IO_BI );
34     return true;
35 }
36
37 bool
38 TcpServer::process()
39 {
40     char buf[1024];
41
42     int len;
43     while ((len = channel->readline( buf, sizeof(buf) )) > 0)
44     {
45         cout << len << ": " << buf;
46     }
47     return true;
48 }
49
50 bool
51 TcpServer::close()
52 {
53     return channel->close();
54 }
55
56
57 int
58 main()
59 {
60     sglog().setLogLevels( SG_ALL, SG_INFO );
61     TcpServer server;
62     server.open();
63     SG_LOG( SG_IO, SG_INFO, "Created TCP server" );
64
65     while (1)
66     {
67         server.process();
68     }
69
70     server.close();
71     return 0;
72 }