aboutsummaryrefslogtreecommitdiff
path: root/src/tests/telnetsrv.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/telnetsrv.cpp')
-rw-r--r--src/tests/telnetsrv.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/tests/telnetsrv.cpp b/src/tests/telnetsrv.cpp
new file mode 100644
index 0000000..39e3217
--- /dev/null
+++ b/src/tests/telnetsrv.cpp
@@ -0,0 +1,85 @@
1#include "bu/server.h"
2#include "bu/protocoltelnet.h"
3#include "bu/client.h"
4
5class MyTelnet : public Bu::ProtocolTelnet
6{
7public:
8 MyTelnet()
9 {
10 }
11
12 virtual ~MyTelnet()
13 {
14 }
15
16 virtual void onNewConnection( Bu::Client *pClient )
17 {
18 Bu::ProtocolTelnet::onNewConnection( pClient );
19
20 //oNAWS.remoteSet();
21 oEcho.localSet();
22 oSuppressGA.remoteSet( true );
23 oSuppressGA.localSet( true );
24 setCanonical();
25 }
26
27 virtual void onSubNAWS( uint16_t iWidth, uint16_t iHeight )
28 {
29 printf("New dim = (%dx%d)\n", iWidth, iHeight );
30 }
31
32 virtual void gotLine( Bu::FString &sLine )
33 {
34 printf("Line: \"%s\"\n", sLine.getStr() );
35 write("\n\r", 2 );
36 }
37
38private:
39
40};
41
42class TelServer : public Bu::Server
43{
44public:
45 TelServer()
46 {
47 }
48
49 virtual ~TelServer()
50 {
51 }
52
53 virtual void onNewConnection( Bu::Client *pClient, int iPort )
54 {
55 printf("New connection.\n");
56
57 pClient->setProtocol( new MyTelnet() );
58 }
59
60 virtual void onClosedConnection( Bu::Client *pClient )
61 {
62 printf("Lost connection.\n");
63
64 delete pClient->getProtocol();
65 }
66
67private:
68
69};
70
71int main( int argc, char *argv[] )
72{
73 TelServer ts;
74
75 ts.addPort( 4000 );
76 ts.setTimeout( 0, 5000 );
77
78 printf("Initializing server on port: 4000\n");
79
80 for(;;)
81 {
82 ts.scan();
83 }
84}
85