diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-11 23:07:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-11 23:07:44 +0000 |
commit | 1291252a7b1317ad2dc13fbeb15f6e9d2d92192c (patch) | |
tree | 5eb88c7cef5417c043b03b34a77334c57286e526 /src/tests/serverticks.cpp | |
parent | 595afe519791894c77c77a949fba7732f4d94872 (diff) | |
download | libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.tar.gz libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.tar.bz2 libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.tar.xz libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.zip |
A new feature has been added to Bu::Server. It's going to be trickier to
implement in Bu::ItoServer, but I'll get to it. Basically you can trigger a
"tick" any time you want and it will propegate as an onTick event to all active
clients. You can also have these generated automatically everytime the system
passes through a polling cycle. In this case, you should never ever write
data to the socket every tick. It will cause your program to go bursurk.
Diffstat (limited to '')
-rw-r--r-- | src/tests/serverticks.cpp | 61 |
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 | |||
5 | class TickProtocol : public Bu::Protocol | ||
6 | { | ||
7 | public: | ||
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 | |||
23 | class TickServer : public Bu::Server | ||
24 | { | ||
25 | public: | ||
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 | |||
45 | int 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 | |||