From 1291252a7b1317ad2dc13fbeb15f6e9d2d92192c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 11 Jan 2009 23:07:44 +0000 Subject: 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. --- src/tests/serverticks.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/tests/serverticks.cpp (limited to 'src/tests') 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 @@ +#include "bu/server.h" +#include "bu/client.h" +#include "bu/protocol.h" + +class TickProtocol : public Bu::Protocol +{ +public: + TickProtocol() + { + } + + virtual ~TickProtocol() + { + } + + virtual void onTick( Bu::Client *pClient ) + { + printf("tick!\n"); + pClient->write("tick!\n"); + } +}; + +class TickServer : public Bu::Server +{ +public: + TickServer() + { + } + + virtual ~TickServer() + { + } + + virtual void onNewConnection( Bu::Client *pClient, int ) + { + pClient->setProtocol( new TickProtocol() ); + } + + virtual void onClosedConnection( Bu::Client *pClient ) + { + delete pClient->getProtocol(); + } +}; + +int main( int , char *[] ) +{ + TickServer ts; + + ts.setTimeout( 1, 0 ); + ts.setAutoTick(); + ts.addPort( 5555 ); + + for(;;) + { + ts.scan(); + sleep( 1 ); + } + + return 0; +} + -- cgit v1.2.3