Changeset 3214 for code/trunk/src/network/ClientConnection.h
- Timestamp:
- Jun 23, 2009, 6:02:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/ClientConnection.h
r3084 r3214 26 26 * 27 27 */ 28 29 // 30 // C++ Interface: ClientConnection 31 // 32 // Description: 33 // 34 // 35 // Author: Oliver Scheuss, (C) 2007 36 // 37 // Copyright: See COPYING file that comes with this distribution 38 // 39 // 28 40 29 #ifndef _ClientConnection_H__ 41 30 #define _ClientConnection_H__ 42 31 43 32 #include "NetworkPrereqs.h" 44 45 #include <string> 46 #include "PacketBuffer.h" 47 48 namespace boost { class thread; } 33 #include "Connection.h" 49 34 50 35 namespace orxonox 51 36 { 52 37 53 const int NETWORK_PORT = 55556; 54 const int NETWORK_CLIENT_MAX_CONNECTIONS = 5; 55 const int NETWORK_CLIENT_WAIT_TIME = 10; 56 const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds 57 const int NETWORK_CLIENT_CHANNELS = 2; 58 59 60 class _NetworkExport ClientConnection{ 38 class _NetworkExport ClientConnection: public Connection{ 61 39 public: 62 ClientConnection(int port, const std::string& address); 63 ClientConnection(int port, const char* address); 64 ~ClientConnection(); 40 ClientConnection(); 41 virtual ~ClientConnection(); 42 43 void setServerAddress( const std::string& serverAddress ); 44 void setPort( unsigned int port ); 45 65 46 ENetEvent *getEvent(); 66 47 // check wheter the packet queue is empty 67 48 bool queueEmpty(); 68 49 // create a new listener thread 69 bool createConnection();70 bool closeConnection();50 virtual bool establishConnection(); 51 virtual bool closeConnection(); 71 52 // add a packet to queue for the server 72 53 bool addPacket(ENetPacket *packet); 73 // send out all queued packets 74 bool sendPackets(); 75 // send out all queued packets and save result in event 76 //bool sendPackets(ENetEvent *event); 77 bool waitEstablished(int milisec); 78 inline bool isConnected(){return established;} 79 inline bool checkConnection(){ return !quit_ && isConnected(); } 54 inline bool isConnected(){ return this->established_; } 80 55 private: 81 ClientConnection(const ClientConnection& copy); // not used 82 bool processData(ENetEvent *event); 83 // implementation of the listener 84 void receiverThread(); //thread2 85 //packetbuffer 86 bool establishConnection(); 56 virtual void addClient(ENetEvent* event); 57 virtual void disconnectPeer(ENetEvent* event); 58 87 59 bool disconnectConnection(); 88 PacketBuffer buffer;89 60 // enet stuff 90 ENetHost *client; 91 ENetAddress *serverAddress; 92 // quit-variable (communication with threads) 93 bool quit_; 94 bool established; 61 ENetAddress *serverAddress_; 62 bool established_; 95 63 // clientlist 96 ENetPeer *server; 97 boost::thread *receiverThread_; 64 ENetPeer *server_; 98 65 }; 99 100 101 102 103 104 105 66 106 67
Note: See TracChangeset
for help on using the changeset viewer.