blob: 80c4dfacd28e06cd83b789114d8b425c5007924a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}
|