Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/ClientConnection.h @ 217

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

-implemented class ClientConnection:

  • implements the network part of a client (analog to ConnectionManager for the server)
  • again there is a receiver-Thread and a buffer
  • (hopefully) clean disconnection and wait for connection

-extended dummyclient (dummyclient2.cc) to use new ClientConnection class
-make target client builds now dummyclient2
-adjusted the Makefile

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