Index: /code/branches/network5/src/libraries/network/Client.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Client.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Client.cc	(revision 7772)
@@ -114,9 +114,7 @@
   }
 
-  bool Client::queuePacket(ENetPacket *packet, int clientID)
-  {
-    bool b = ClientConnection::addPacket(packet);
-    assert(b);
-    return b;
+  void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
+  {
+    ClientConnection::addPacket(packet, channelID);
   }
 
@@ -170,5 +168,5 @@
       }
     }
-    sendPackets(); // flush the enet queue
+//     sendPackets(); // flush the enet queue
 
     Connection::processQueue();
@@ -180,5 +178,5 @@
     }
     gamestate->cleanup();
-    Connection::sendPackets();
+//     Connection::sendPackets();
 
     return;
Index: /code/branches/network5/src/libraries/network/Client.h
===================================================================
--- /code/branches/network5/src/libraries/network/Client.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Client.h	(revision 7772)
@@ -78,5 +78,5 @@
     void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
     bool closeConnection();
-    bool queuePacket(ENetPacket *packet, int clientID);
+    void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID);
     bool processChat(const std::string& message, unsigned int playerID);
     virtual bool chat(const std::string& message);
Index: /code/branches/network5/src/libraries/network/ClientConnection.cc
===================================================================
--- /code/branches/network5/src/libraries/network/ClientConnection.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/ClientConnection.cc	(revision 7772)
@@ -99,4 +99,5 @@
       {
         this->established_=true;
+        Connection::startCommunicationThread();
         return true;
       }
@@ -112,4 +113,5 @@
       return true;
     this->established_ = false;
+    Connection::stopCommunicationThread();
     enet_peer_disconnect(this->server_, 0);
     for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
@@ -138,8 +140,8 @@
 
 
-  bool ClientConnection::addPacket(ENetPacket *packet) {
+  void ClientConnection::addPacket(ENetPacket *packet, uint8_t channelID) {
     assert( this->server_ );
     assert( packet );
-    return Connection::addPacket( packet, this->server_ );
+    return Connection::addPacket( packet, this->server_, channelID );
   }
 
Index: /code/branches/network5/src/libraries/network/ClientConnection.h
===================================================================
--- /code/branches/network5/src/libraries/network/ClientConnection.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/ClientConnection.h	(revision 7772)
@@ -51,5 +51,5 @@
     virtual bool closeConnection();
     // add a packet to queue for the server
-    bool addPacket(ENetPacket *packet);
+    void addPacket(ENetPacket *packet, uint8_t channelID);
     inline bool isConnected(){ return this->established_; }
   protected:
Index: /code/branches/network5/src/libraries/network/Connection.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Connection.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Connection.cc	(revision 7772)
@@ -30,55 +30,158 @@
 
 #include <cassert>
+#include <deque>
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
+#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/date_time.hpp>
+
 #include "packet/Packet.h"
 
 namespace orxonox
 {
-//   Connection *Connection::instance_=0;
+  const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20);
 
   Connection::Connection():
-    host_(0)
-  {
-//     assert(instance_==0);
-//     Connection::instance_=this;
+    host_(0), bCommunicationThreadRunning_(false)
+  {
     enet_initialize();
     atexit(enet_deinitialize);
-  }
-
-  Connection::~Connection(){
-//     Connection::instance_=0;
-  }
-
-  int Connection::service(ENetEvent* event) {
-    return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
-  }
-
-  void Connection::disconnectPeer(ENetPeer *peer) {
-    enet_peer_disconnect(peer, 0);
-  }
-
-  bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
-      return false;
-    else
-      return true;
-  }
-
-  bool Connection::sendPackets() {
-    if ( /*!Connection::instance_ || */this->host_==NULL )
-      return false;
-    enet_host_flush(this->host_);
-    return true;
-  }
-
-  void Connection::processQueue() {
+    this->incomingEventsMutex_ = new boost::mutex;
+    this->outgoingEventsMutex_ = new boost::mutex;
+  }
+
+  Connection::~Connection()
+  {
+    delete this->incomingEventsMutex_;
+    delete this->outgoingEventsMutex_;
+  }
+
+  void Connection::startCommunicationThread()
+  {
+    this->bCommunicationThreadRunning_ = true;
+    this->communicationThread_ = new boost::thread(&Connection::communicationThread, this);
+  }
+  
+  void Connection::stopCommunicationThread()
+  {
+    this->bCommunicationThreadRunning_ = false;
+    if( !this->communicationThread_->timed_join(NETWORK_COMMUNICATION_THREAD_WAIT_TIME) )
+    {
+      // force thread to stop
+      this->communicationThread_->interrupt();
+    }
+    delete this->communicationThread_;
+  }
+
+
+//   int Connection::service(ENetEvent* event) {
+//     return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+//   }
+
+  void Connection::disconnectPeer(ENetPeer *peer)
+  {
+    outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
+  }
+
+  void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)
+  {
+    outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
+  }
+  
+  void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID)
+  {
+    outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
+  }
+
+  
+  void Connection::communicationThread()
+  {
+    COUT(0) << "starting communication thread" << endl;
     ENetEvent event;
-
-    assert(this->host_);
-
-    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    
+    while( bCommunicationThreadRunning_ )
     {
-      switch(event.type){
+      // Receive all pending incoming Events (such as packets, connects and disconnects)
+      while( enet_host_check_events( this->host_, &event ) > 0 )
+      {
+//         COUT(0) << "incoming event" << endl;
+        // received an event
+        this->incomingEventsMutex_->lock();
+        this->incomingEvents_.push_back(event);
+        this->incomingEventsMutex_->unlock();
+      }
+      
+      // Send all waiting outgoing packets
+      this->outgoingEventsMutex_->lock();
+      uint32_t outgoingEventsCount = this->outgoingEvents_.size();
+      this->outgoingEventsMutex_->unlock();
+      while( outgoingEventsCount > 0 )
+      {
+//         COUT(0) << "outgoing event" << endl;
+        this->outgoingEventsMutex_->lock();
+        outgoingEvent outEvent = this->outgoingEvents_.front();
+        this->outgoingEvents_.pop_front();
+        this->outgoingEventsMutex_->unlock();
+        
+        switch( outEvent.type )
+        {
+          case outgoingEventType::sendPacket:
+            enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet );
+            break;
+          case outgoingEventType::disconnectPeer:
+            enet_peer_disconnect(outEvent.peer, 0);
+            break;
+          case outgoingEventType::broadcastPacket:
+            enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet );
+            break;
+          default:
+            assert(0);
+        }
+        this->outgoingEventsMutex_->lock();
+        outgoingEventsCount = this->outgoingEvents_.size();
+        this->outgoingEventsMutex_->unlock();
+      }
+      
+      // Wait for incoming events (at most NETWORK_WAIT_TIMEOUT ms)
+      if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+      {
+//         COUT(0) << "incoming event after wait" << endl;
+        //received an event
+        this->incomingEventsMutex_->lock();
+        this->incomingEvents_.push_back(event);
+        this->incomingEventsMutex_->unlock();
+      }
+    }
+  }
+
+  void Connection::processQueue()
+  {
+    ENetEvent event;
+
+    this->incomingEventsMutex_->lock();
+    uint32_t incomingEventsCount = this->incomingEvents_.size();
+    this->incomingEventsMutex_->unlock();
+    while( incomingEventsCount > 0 )
+    {
+      this->incomingEventsMutex_->lock();
+      event = this->incomingEvents_.front();
+      this->incomingEvents_.pop_front();
+      this->incomingEventsMutex_->unlock();
+      
+      switch(event.type)
+      {
         // log handling ================
         case ENET_EVENT_TYPE_CONNECT:
@@ -89,4 +192,5 @@
           break;
         case ENET_EVENT_TYPE_RECEIVE:
+//           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
           processPacket( &event );
           break;
@@ -94,8 +198,13 @@
           break;
       }
+      
+      this->incomingEventsMutex_->lock();
+      incomingEventsCount = this->incomingEvents_.size();
+      this->incomingEventsMutex_->unlock();
     }
   }
 
-  bool Connection::processPacket(ENetEvent* event) {
+  bool Connection::processPacket(ENetEvent* event)
+  {
     packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
     return p->process();
Index: /code/branches/network5/src/libraries/network/Connection.h
===================================================================
--- /code/branches/network5/src/libraries/network/Connection.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Connection.h	(revision 7772)
@@ -43,18 +43,45 @@
 #include "NetworkPrereqs.h"
 
+#include <deque>
+
+namespace boost
+{
+  class thread;
+  class mutex;
+}
+
 namespace orxonox
 {
-    const unsigned int NETWORK_PORT = 55556;
-    const unsigned int NETWORK_MAX_CONNECTIONS = 50;
-    const unsigned int NETWORK_WAIT_TIMEOUT = 0;
-    const unsigned int NETWORK_DEFAULT_CHANNEL = 0;
-    const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
-
-  class _NetworkExport Connection{
+  const unsigned int NETWORK_PORT                   = 55556;
+  const unsigned int NETWORK_MAX_CONNECTIONS        = 50;
+  const unsigned int NETWORK_WAIT_TIMEOUT           = 1;
+  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
+  
+  namespace outgoingEventType
+  {
+    enum Value
+    {
+      sendPacket      = 1,
+      disconnectPeer  = 2,
+      broadcastPacket = 3
+    };
+    
+  }
+  
+  struct _NetworkExport outgoingEvent
+  {
+    ENetPeer*                 peer;
+    outgoingEventType::Value  type;
+    ENetPacket*               packet;
+    ENetChannelID             channelID;
+  };
+  
+  class _NetworkExport Connection
+  {
   public:
     virtual ~Connection();
 
-    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
-    bool sendPackets();
+    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
+    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
     ENetHost* getHost(){ return this->host_; }
 
@@ -63,5 +90,8 @@
 //     static Connection* getInstance(){ return Connection::instance_; }
 
-    int service(ENetEvent* event);
+//     int service(ENetEvent* event);
+    void startCommunicationThread();
+    void stopCommunicationThread();
+    void communicationThread();
     virtual void disconnectPeer(ENetPeer *peer);
 
@@ -71,7 +101,13 @@
     virtual bool processPacket(ENetEvent* event);
 
-    ENetHost *host_;
+    ENetHost*                   host_;
+    boost::mutex*               incomingEventsMutex_;
+    boost::mutex*               outgoingEventsMutex_;
   private:
-    ENetAddress *bindAddress_;
+    boost::thread*              communicationThread_;
+    bool                        bCommunicationThreadRunning_;
+    ENetAddress*                bindAddress_;
+    std::deque<ENetEvent>       incomingEvents_;
+    std::deque<outgoingEvent>   outgoingEvents_;
 
 //     static Connection *instance_;
Index: /code/branches/network5/src/libraries/network/Host.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Host.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Host.cc	(revision 7772)
@@ -76,16 +76,13 @@
   * @return success?
   */
-  bool Host::addPacket(ENetPacket *packet, int clientID)
+  void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    bool result = true;
     for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     {
       if( (*it)->isActive() )
       {
-        if( !(*it)->queuePacket(packet, clientID) )
-          result = false;
+        (*it)->queuePacket(packet, clientID, channelID);
       }
     }
-    return result;
   }
 
Index: /code/branches/network5/src/libraries/network/Host.h
===================================================================
--- /code/branches/network5/src/libraries/network/Host.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Host.h	(revision 7772)
@@ -54,5 +54,5 @@
     //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
     //virtual bool sendChat(packet::Chat *chat)=0;
-    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
+    virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)=0;
     virtual bool chat(const std::string& message)=0;
     virtual bool broadcast(const std::string& message)=0;
@@ -71,5 +71,5 @@
 //     static Host* getInstance(){ return instance_; }
     static bool running(){ return instances_s.size(); }
-    static bool addPacket(ENetPacket *packet, int clientID=0);
+    static void addPacket(ENetPacket* packet, int clientID = NETWORK_PEER_ID_SERVER, uint8_t channelID = 0);
     //static bool chat(std::string& message);
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
Index: /code/branches/network5/src/libraries/network/NetworkPrereqs.h
===================================================================
--- /code/branches/network5/src/libraries/network/NetworkPrereqs.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/NetworkPrereqs.h	(revision 7772)
@@ -64,10 +64,12 @@
 namespace orxonox
 {
-  static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
-  static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
+  static const unsigned int GAMESTATEID_INITIAL       = static_cast<unsigned int>(-1);
+  static const unsigned int CLIENTID_UNKNOWN          = static_cast<unsigned int>(-2);
   extern const char* LAN_DISCOVERY_MESSAGE;
   extern const char* LAN_DISCOVERY_ACK;
-  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
-  static const unsigned int NETWORK_PEER_ID_SERVER = 0;
+  static const unsigned int LAN_DISCOVERY_PORT        = 55557;
+  static const unsigned int NETWORK_PEER_ID_SERVER    = 0;
+  static const unsigned int NETWORK_CHANNEL_DEFAULT   = 0;
+  static const unsigned int NETWORK_CHANNEL_RELIABLE  = 1;
 }
 
@@ -98,13 +100,14 @@
 // from ENet
 struct _ENetPeer;
-typedef _ENetPeer ENetPeer;
+typedef _ENetPeer     ENetPeer;
 struct _ENetPacket;
-typedef _ENetPacket ENetPacket;
+typedef _ENetPacket   ENetPacket;
 struct _ENetEvent;
-typedef _ENetEvent ENetEvent;
+typedef _ENetEvent    ENetEvent;
 struct _ENetHost;
-typedef _ENetHost ENetHost;
+typedef _ENetHost     ENetHost;
 struct _ENetAddress;
-typedef _ENetAddress ENetAddress;
+typedef _ENetAddress  ENetAddress;
+typedef uint8_t       ENetChannelID;
 
 namespace orxonox
@@ -162,3 +165,9 @@
 }
 
+namespace boost
+{
+  class mutex;
+  class thread;
+}
+
 #endif /* _NetworkPrereqs_H__ */
Index: /code/branches/network5/src/libraries/network/Server.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Server.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Server.cc	(revision 7772)
@@ -229,11 +229,11 @@
         updateGamestate();
       }
-      sendPackets(); // flush the enet queue
-    }
-  }
-
-  bool Server::queuePacket(ENetPacket *packet, int clientID)
-  {
-    return ServerConnection::addPacket(packet, clientID);
+//       sendPackets(); // flush the enet queue
+    }
+  }
+
+  void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
+  {
+    ServerConnection::addPacket(packet, clientID, channelID);
   }
 
Index: /code/branches/network5/src/libraries/network/Server.h
===================================================================
--- /code/branches/network5/src/libraries/network/Server.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/Server.h	(revision 7772)
@@ -64,5 +64,5 @@
     void close();
     bool processChat(const std::string& message, unsigned int playerID);
-    bool queuePacket(ENetPacket *packet, int clientID);
+    void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);
     void update(const Clock& time);
     unsigned int getRTT(unsigned int clientID);
Index: /code/branches/network5/src/libraries/network/ServerConnection.cc
===================================================================
--- /code/branches/network5/src/libraries/network/ServerConnection.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/ServerConnection.cc	(revision 7772)
@@ -49,5 +49,6 @@
   }
 
-  ServerConnection::~ServerConnection(){
+  ServerConnection::~ServerConnection()
+  {
     if ( this->bListening_ )
       closeListener();
@@ -55,5 +56,6 @@
   }
 
-  void ServerConnection::setBindAddress( const std::string& bindAddress ) {
+  void ServerConnection::setBindAddress( const std::string& bindAddress )
+  {
     if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
         COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
@@ -64,5 +66,6 @@
   }
 
-  bool ServerConnection::openListener() {
+  bool ServerConnection::openListener()
+  {
     this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
     if ( this->host_ == NULL )
@@ -78,9 +81,12 @@
     else
         COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+    
+    Connection::startCommunicationThread();
 
     return true;
   }
 
-  bool ServerConnection::closeListener() {
+  bool ServerConnection::closeListener()
+  {
     this->bListening_=false;
     disconnectClients();
@@ -89,8 +95,9 @@
   }
 
-  bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
+  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
+  {
     if ( clientID == CLIENTID_UNKNOWN )
     {
-      return addPacketAll(packet);
+      broadcastPacket(packet, channelID);
     }
     else
@@ -99,15 +106,7 @@
       if(!temp){
         COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
-        return false;
       }
-      return Connection::addPacket(packet, temp->getPeer());
+      Connection::addPacket(packet, temp->getPeer(), channelID);
     }
-  }
-
-  bool ServerConnection::addPacketAll(ENetPacket *packet) {
-//     if ( !Connection::getInstance() )
-//       return false;
-    enet_host_broadcast( Connection::getHost(), 0, packet);
-    return true;
   }
 
@@ -117,5 +116,6 @@
   }
 
-  void ServerConnection::disconnectClient(int clientID){
+  void ServerConnection::disconnectClient(int clientID)
+  {
     ClientInformation *client = ClientInformation::findClient(clientID);
     if(client)
@@ -123,28 +123,11 @@
   }
 
-  void ServerConnection::disconnectClients() {
-    ENetEvent event;
+  void ServerConnection::disconnectClients()
+  {
     ClientInformation *temp = ClientInformation::getBegin();
-    while(temp!=0){
+    while(temp!=0)
+    {
       ServerConnection::disconnectClient( temp );
       temp = temp->next();
-    }
-    temp = ClientInformation::getBegin();
-    while( temp!=0 ){
-      if( service( &event ) )
-      {
-        switch (event.type)
-        {
-        case ENET_EVENT_TYPE_NONE: break;
-        case ENET_EVENT_TYPE_CONNECT: break;
-        case ENET_EVENT_TYPE_RECEIVE:
-          enet_packet_destroy(event.packet);
-          break;
-        case ENET_EVENT_TYPE_DISCONNECT:
-          removePeer( &event );
-          temp = ClientInformation::getBegin();
-          break;
-        }
-      }
     }
     return;
@@ -152,13 +135,16 @@
 
 
-  int ServerConnection::getClientID(ENetPeer* peer) {
+  int ServerConnection::getClientID(ENetPeer* peer)
+  {
     return getClientID(&(peer->address));
   }
 
-  int ServerConnection::getClientID(ENetAddress* address) {
+  int ServerConnection::getClientID(ENetAddress* address)
+  {
     return ClientInformation::findClient(address)->getID();
   }
 
-  ENetPeer *ServerConnection::getClientPeer(int clientID) {
+  ENetPeer *ServerConnection::getClientPeer(int clientID)
+  {
     return ClientInformation::findClient(clientID)->getPeer();
   }
Index: /code/branches/network5/src/libraries/network/ServerConnection.h
===================================================================
--- /code/branches/network5/src/libraries/network/ServerConnection.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/ServerConnection.h	(revision 7772)
@@ -56,6 +56,5 @@
     bool openListener();
     bool closeListener();
-    bool addPacket(ENetPacket *packet, unsigned int ID);
-    bool addPacketAll(ENetPacket *packet);
+    void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID);
     virtual void disconnectClient(ClientInformation *client);
     void disconnectClient(int clientID);
Index: /code/branches/network5/src/libraries/network/packet/Packet.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Packet.cc	(revision 7771)
+++ /code/branches/network5/src/libraries/network/packet/Packet.cc	(revision 7772)
@@ -35,4 +35,5 @@
 #include <enet/enet.h>
 #include <boost/static_assert.hpp>
+#include <boost/thread/mutex.hpp>
 
 #include "util/Debug.h"
@@ -61,4 +62,5 @@
 
 std::map<size_t, Packet *> Packet::packetMap_;
+boost::mutex Packet::packetMapMutex_;
 
 Packet::Packet()
@@ -142,5 +144,7 @@
       // Assures we don't create a packet and destroy it right after in another thread
       // without having a reference in the packetMap_
+      Packet::packetMapMutex_.lock();
       packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
+      Packet::packetMapMutex_.unlock();
     }
   }
@@ -164,6 +168,8 @@
 //  ENetPacket *temp = enetPacket_;
 //  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
-  if(!Host::addPacket( enetPacket_, clientID_))
-    enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually
+  if( this->flags_ & PacketFlag::Reliable )
+    Host::addPacket( enetPacket_, clientID_, 0);
+  else
+    Host::addPacket( enetPacket_, clientID_, 0);
   return true;
 }
@@ -228,4 +234,5 @@
 void Packet::deletePacket(ENetPacket *enetPacket){
   // Get our Packet from a global map with all Packets created in the send() method of Packet.
+  Packet::packetMapMutex_.lock();
   std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
   assert(it != packetMap_.end());
@@ -234,4 +241,5 @@
   delete it->second;
   packetMap_.erase(it);
+  Packet::packetMapMutex_.unlock();
 //   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
 }
Index: /code/branches/network5/src/libraries/network/packet/Packet.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Packet.h	(revision 7771)
+++ /code/branches/network5/src/libraries/network/packet/Packet.h	(revision 7772)
@@ -96,4 +96,5 @@
   private:
     static std::map<size_t, Packet *> packetMap_;
+    static boost::mutex               packetMapMutex_;
     ENetPacket *enetPacket_;
 };
