aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/serverticks.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tests/serverticks.cpp b/src/tests/serverticks.cpp
new file mode 100644
index 0000000..80c4dfa
--- /dev/null
+++ b/src/tests/serverticks.cpp
@@ -0,0 +1,61 @@
1#include "bu/server.h"
2#include "bu/client.h"
3#include "bu/protocol.h"
4
5class TickProtocol : public Bu::Protocol
6{
7public:
8 TickProtocol()
9 {
10 }
11
12 virtual ~TickProtocol()
13 {
14 }
15
16 virtual void onTick( Bu::Client *pClient )
17 {
18 printf("tick!\n");
19 pClient->write("tick!\n");
20 }
21};
22
23class TickServer : public Bu::Server
24{
25public:
26 TickServer()
27 {
28 }
29
30 virtual ~TickServer()
31 {
32 }
33
34 virtual void onNewConnection( Bu::Client *pClient, int )
35 {
36 pClient->setProtocol( new TickProtocol() );
37 }
38
39 virtual void onClosedConnection( Bu::Client *pClient )
40 {
41 delete pClient->getProtocol();
42 }
43};
44
45int main( int , char *[] )
46{
47 TickServer ts;
48
49 ts.setTimeout( 1, 0 );
50 ts.setAutoTick();
51 ts.addPort( 5555 );
52
53 for(;;)
54 {
55 ts.scan();
56 sleep( 1 );
57 }
58
59 return 0;
60}
61