source: osgVisual/include/cluster/dataIO_clusterENet_implementation.h @ 65

Last change on this file since 65 was 65, checked in by Torben Dannhauer, 14 years ago

new cluster implementation added: ENet
ENet is a reliable UDP implementation with quite simple usage and high performance for transmission with small or medium size packet.

File size: 1.7 KB
Line 
1#pragma once
2#if _MSC_VER > 1000
3        #pragma warning(disable:4146)
4#endif // _MSC_VER > 1000
5
6#include <enet/enet.h>
7#include <iostream>
8#include <string>
9#include <vector>
10
11
12
13class ENet_implementation
14{
15public:
16        ENet_implementation();
17        ~ENet_implementation();
18
19        enum role {SERVER, CLIENT};
20
21        bool init( ENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 );      // client & server                                                              // Done
22        bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0,  int channelToAlloc_=2 );   // only as client                                                                       // Done
23        void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false );   // by PeerID    // Done
24        void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_=false );    // by peer name // Done
25        void broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_=false );      // only as server.                                      // Done
26        void processEvents( int timeout_ms_ = 0 );                                                                                                                                                                              // Done
27       
28        virtual inline void onReceivePacket(ENetEvent* event_);
29        virtual inline void onConnect(ENetEvent* event_);               // This function will be called only by the host waiting for the connection.
30        virtual inline void onDisconnect(ENetEvent* event_);
31
32protected:
33        unsigned short port;
34        ENet_implementation::role currentRole;
35        static int activeENetInstances;
36        bool serverInitialized; // shows if the complete server is initialized. (After init())
37        ENetAddress address;
38    ENetHost* host;
39        std::vector<ENetPeer*> peerList;        // client: only one peer to server,    Server: multiple peers for all clients
40        ENetEvent event;
41};
Note: See TracBrowser for help on using the repository browser.