Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/network/ClientConnection.h @ 859

Last change on this file since 859 was 859, checked in by landauf, 16 years ago

more or less a copy of the trunk

File size: 1.6 KB
Line 
1//
2// C++ Interface: ClientConnection
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 _ClientConnection_H__
13#define _ClientConnection_H__
14
15#include <string>
16#include <enet/enet.h>
17
18#include "NetworkPrereqs.h"
19#include "PacketBuffer.h"
20
21namespace network
22{
23
24#define NETWORK_PORT 55556
25#define NETWORK_CLIENT_MAX_CONNECTIONS 5
26#define NETWORK_CLIENT_TIMEOUT 10
27#define NETWORK_SEND_WAIT 5
28#define NETWORK_CLIENT_CHANNELS 2
29
30
31  class ClientConnection{
32  public:
33    ClientConnection(int port, std::string address);
34    ClientConnection(int port, const char* address);
35    ENetPacket *getPacket(ENetAddress &address); // thread1
36    ENetPacket *getPacket(); // thread1
37    // check wheter the packet queue is empty
38    bool queueEmpty();
39    // create a new listener thread
40    bool createConnection();
41    bool closeConnection();
42    // add a packet to queue for the server
43    bool addPacket(ENetPacket *packet);
44    // send out all queued packets
45    bool sendPackets();
46    // send out all queued packets and save result in event
47    bool sendPackets(ENetEvent *event);
48    bool waitEstablished(int milisec);
49  private:
50    bool processData(ENetEvent *event);
51    // implementation of the listener
52    void receiverThread(); //thread2
53    //packetbuffer
54    bool establishConnection();
55    bool disconnectConnection();
56    PacketBuffer buffer;
57    // enet stuff
58    ENetHost *client;
59    ENetAddress serverAddress;
60    // quit-variable (communication with threads)
61    bool quit;
62    bool established;
63    // clientlist
64    ENetPeer *server;
65  };
66
67
68
69
70
71
72
73
74}
75
76#endif /* _ClientConnection_H__ */
Note: See TracBrowser for help on using the repository browser.