aboutsummaryrefslogtreecommitdiff
path: root/src/tests/serverticks.cpp
blob: 3aad746526e9ae62955cbade9cc29cd72056ccd8 (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
62
63
64
65
66
67
68
69
/*
 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/server.h"
#include "bu/client.h"
#include "bu/protocol.h"
#include <unistd.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;
}