Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/ConnectionManager.h @ 196

Last change on this file since 196 was 196, checked in by scheusso, 16 years ago

created a dummyserver and dummyclient in order to test ConnectionManager and PacketBuffer with enet and boost_thread\n Makefile is used to build server and client

File size: 2.1 KB
Line 
1//
2// C++ Interface: ConnectionManager
3//
4// Description:
5//
6//
7// Author:  Oliver Scheuss, (C) 2007
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef NETWORK_CONNECTIONMANAGER_H
13#define NETWORK_CONNECTIONMANAGER_H
14
15#include <iostream>
16// enet library for networking support
17#include <enet/enet.h>
18// boost.thread library for multithreading support
19#include <boost/thread/thread.hpp>
20#include <boost/bind.hpp>
21// headerfile
22#include "network/ConnectionManager.h"
23#include "network/PacketBuffer.h"
24
25namespace network{
26  //
27#define NETWORK_PORT 5555
28#define NETWORK_MAX_CONNECTIONS 50
29#define NETWORK_WAIT_TIMEOUT 5000
30#define NETWORK_SEND_WAIT 5
31  //just some defines to make life easier ;)
32// #define ENetEvent std::ENetEvent
33// #define ENetHost std::ENetHost
34// #define ENetAddress std::ENetAddress
35// #define ENetPeer std::ENetPeer
36 
37  struct ClientList{
38    ENetEvent *event;
39    int ID;
40    ClientList *next;
41  };
42 
43  class ConnectionManager{
44    public:
45    ConnectionManager();
46    ConnectionManager(int port, int address);
47    ENetPacket *getPacket(); // thread1
48    // check wheter the packet queue is empty
49    bool queueEmpty();
50    // create a new listener thread
51    void createListener();
52    bool quitListener();
53    // add a packet to queue for a specific client peer
54    bool addPacket(ENetPacket *packet, ENetPeer *peer);
55    // add ad packet to queue for a specific client ID
56    bool addPacket(ENetPacket *packet, int ID);
57    // add a packet to queue for all clients
58    bool addPacketAll(ENetPacket *packet);
59    // send out all queued packets
60    bool sendPackets(ENetEvent *event);
61    private:
62    bool clientDisconnect(ENetPeer *peer);
63    bool processData(ENetEvent *event);
64    bool addClient(ENetEvent *event);
65    // implementation of the listener
66    void receiverThread(); //thread2
67    //packetbuffer
68    PacketBuffer buffer;
69    // enet stuff
70    ENetHost *server;
71    ENetAddress bindAddress;
72    // quit-variable (communication with threads)
73    bool quit;
74    // clientlist
75    ClientList *client;
76//     thread group
77//     boost::thread_group threads;
78  };
79 
80 
81 
82 
83 
84 
85 
86 
87}
88
89#endif
Note: See TracBrowser for help on using the repository browser.