Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 204


Ignore:
Timestamp:
Nov 14, 2007, 2:58:23 PM (17 years ago)
Author:
scheusso
Message:

changed packetbuffer and conenctionmanager to remember the client id/adjustet dummyserver/client

Location:
code/branches/network/src/network
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/ConnectionManager.cc

    r196 r204  
    3535 
    3636 
    37   ENetPacket *ConnectionManager::getPacket(){
     37  ENetPacket *ConnectionManager::getPacket(ENetAddress &address){
    3838    if(!buffer.isEmpty())
    39       return buffer.pop();
     39      return buffer.pop(address);
    4040    else
    4141        return NULL;
     
    127127        break;
    128128      case ENET_EVENT_TYPE_RECEIVE:
    129         std::cout << event.packet->data << std::endl;
    130129        processData(&event);
    131130        break;
     
    143142    // just add packet to the buffer
    144143    // this can be extended with some preprocessing
    145     return buffer.push(event->packet);
     144    return buffer.push(event);
    146145  }
    147146 
  • code/branches/network/src/network/ConnectionManager.h

    r196 r204  
    4545    ConnectionManager();
    4646    ConnectionManager(int port, int address);
    47     ENetPacket *getPacket(); // thread1
     47    ENetPacket *getPacket(ENetAddress &address); // thread1
    4848    // check wheter the packet queue is empty
    4949    bool queueEmpty();
  • code/branches/network/src/network/Makefile

    r196 r204  
    22
    33# Link command:
    4 server: clean PacketBuffer.o ConnectionManager.o dummyserver.o
    5         g++ ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread -g
     4server: clean PacketBuffer.o ConnectionManager.o dummyserver.o PacketDecoder.o PacketGenerator.o
     5        g++ PacketDecoder.o PacketGenerator.o ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread -g
    66
    77dummyserver.o:
     
    1313PacketBuffer.o:
    1414        g++ -c PacketBuffer.cc -o PacketBuffer.o -g
     15PacketGenerator.o:
     16        g++ -c PacketGenerator.cc -o PacketGenerator.o -g
     17PacketDecoder.o:
     18        g++ -c PacketDecoder.cc -o PacketDecoder.o -g
     19
    1520
    1621clean:
    1722        rm -rf *.o
    1823
    19 client:
    20         g++ dummyclient.cc -o client -lenet
     24client: PacketGenerator.o
     25        g++ dummyclient.cc PacketGenerator.o -o client -lenet -g
  • code/branches/network/src/network/PacketBuffer.cc

    r196 r204  
    2121 
    2222
    23 bool PacketBuffer::push(ENetPacket *pck){
     23bool PacketBuffer::push(ENetEvent *ev){
    2424  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    2525//   if(closed)
    2626//     return false;
    27   // also works if fifo is null (queue empty)
    28   // just to be sure last is really the last element
    29   /*if(last!=NULL)
    30     while(last->next!=NULL)
    31       last=last->next;*/
    3227  // first element?
    3328  if(first==NULL){
     
    3631    last->next=NULL;
    3732    // change this!!!!!!!
    38     last->packet = pck;
     33    last->packet = ev->packet;
     34    last->address = ev->peer->address;
    3935    } else {
    4036    //insert a new element at the bottom
     
    4440    last->next=NULL;
    4541    // save the packet to the new element
    46     last->packet = pck;
     42    last->packet = ev->packet;
     43    last->address = ev->peer->address;
    4744  }
    4845  return true;
     
    6461}
    6562
     63ENetPacket *PacketBuffer::pop(ENetAddress &address){
     64  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     65  if(first!=NULL /*&& !closed*/){
     66    QueueItem *temp = first;
     67    // get packet
     68    ENetPacket *pck=first->packet;
     69    address = first->address;
     70    // remove first element
     71    first = first->next;
     72    delete temp;
     73    return pck;
     74  } else{
     75    return NULL;
     76  }
     77}
     78
    6679bool PacketBuffer::isEmpty(){
    6780  return (first==NULL);
     
    7184  QueueItem *temp=first;
    7285  while(temp!=NULL){
    73     std::cout << temp->packet->data << std::endl;
     86//    std::cout << temp->packet->data << std::endl;
    7487    temp=temp->next;
    7588  }
  • code/branches/network/src/network/PacketBuffer.h

    r196 r204  
    3131struct QueueItem{
    3232  ENetPacket *packet;
     33  ENetAddress address;
    3334  QueueItem *next;
    3435};
     
    4344  // pops a packet from the queue
    4445  ENetPacket *pop();
     46  ENetPacket *pop(ENetAddress &address);
    4547  // pushs a packet to the queue
    46   bool push(ENetPacket *pck);
     48  bool push(ENetEvent *ev);
    4749 
    4850private:
  • code/branches/network/src/network/dummyclient.cc

    r200 r204  
    66#include <iostream>
    77#include <enet/enet.h>
     8#include "network/PacketManager.h"
    89
    910using namespace std;
     
    1415  ENetEvent event;
    1516  ENetPeer *peer;
     17  network::PacketGenerator pck;
    1618
    1719  enet_initialize();
     
    4446  for(int i=0; i<10; i++){
    4547        // weihnachtsmann bringt packete
    46     ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
     48    //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
    4749        // extend the packet and append the string foo to it
    4850        // send packet to peer on channel id 0
    49     enet_peer_send(peer, 1, packet);
     51    enet_peer_send(peer, 1, pck.chatMessage("test"));
    5052        // keep the timeout very small for low delay
    5153    if(enet_host_service(client, &event, 1)==0){
  • code/branches/network/src/network/dummyserver.cc

    r196 r204  
    88#include "enet/enet.h"
    99#include "network/ConnectionManager.h"
     10#include "network/PacketManager.h"
    1011
    1112using namespace network;
     
    1516  bool quit=false;
    1617  ENetPacket *packet;
     18  ENetEvent event;
    1719  server.createListener();
     20 
     21  PacketDecoder dec;
     22 
    1823  while(!quit){
    1924    if(server.queueEmpty())
    2025      usleep(100);
    2126    else{
    22       packet=server.getPacket();
     27      ENetAddress addr;
     28      packet=server.getPacket(addr);
    2329      if(packet==NULL){
    2430        // there was some error
     
    2632        quit=true;
    2733      }
    28       else
    29         std::cout << "We received: " << packet->data << std::endl;
     34      else{
     35        //std::cout << "We received: " << packet->data << std::endl;
     36        dec.elaborate(packet, 1);
     37      }
    3038    }
    3139  }
Note: See TracChangeset for help on using the changeset viewer.