Index: /branches/network/src/lib/network/network_protocol.cc
===================================================================
--- /branches/network/src/lib/network/network_protocol.cc	(revision 5808)
+++ /branches/network/src/lib/network/network_protocol.cc	(revision 5809)
@@ -41,5 +41,5 @@
   /* set the class id for the base object */
   this->setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol");
-  this->headerLength = HEADER_LENGTH;
+  this->headerLength = sizeof(Header);
 }
 
@@ -65,5 +65,5 @@
   printf("NetworkProtocol: create header length = %i, bufferLength = %i\n", length, bufferLength);
   //If there isn't enough space for the header return -1
-  if (length + headerLength > bufferLength)
+  if (length + this->headerLength > bufferLength)
     return -1;
 
@@ -71,11 +71,23 @@
 //     printf("send byte[%i]=%u\n", i, data[i]);
 
+
   //Create space for the header
   for( int i = length - 1; i >= 0; i--)
-    data[i + headerLength] = data[i];
+    data[i + this->headerLength] = data[i];
 
-  //Include header
+  //Now create the header
+  /* protocol identifier */
   data[0] = 255;
-  return length + headerLength;
+  /* version number */
+  data[1] = 0;
+  /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
+  data[2] = (byte)source.getClassID();
+  /* receiver ID */
+  data[3] = remoteID;
+  /* data length*/
+  data[4] = length;
+
+
+  return length + this->headerLength;
 }
 
@@ -100,8 +112,16 @@
   //Extract header
   Header h;
+  //&h = data;
+
   h.protocol = data[0];
+  /* version number */
+  h.version = data[1];
+  /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
+  h.senderID = data[2];
+  /* receiver ID */
+  h.receiverID = data[3];
+  /* data length*/
+  h.length = data[4];
 
-  h.length = length - headerLength;
-  h.data = data;
 
 //   for(int i = 0; i < length; i++)
@@ -109,6 +129,6 @@
 
   //Remove header
-  for (int i = headerLength; i < length; i++)
-    data[i - headerLength] = data[i];
+//   for (int i = headerLength; i < length; i++)
+//     data[i - headerLength] = data[i];
 
   return h;
Index: /branches/network/src/lib/network/network_protocol.h
===================================================================
--- /branches/network/src/lib/network/network_protocol.h	(revision 5808)
+++ /branches/network/src/lib/network/network_protocol.h	(revision 5809)
@@ -20,5 +20,4 @@
   byte receiverID;
   byte length;
-  byte* data;
 };
 
Index: /branches/network/src/lib/network/network_stream.cc
===================================================================
--- /branches/network/src/lib/network/network_stream.cc	(revision 5808)
+++ /branches/network/src/lib/network/network_stream.cc	(revision 5809)
@@ -78,4 +78,5 @@
   /* set the class id for the base object */
   this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
+  this->state = NET_REC_HEADER;
 }
 
@@ -95,5 +96,5 @@
 void NetworkStream::processData()
 {
-  int ret = 0;
+  int dataLength = 0;
 
   /* DOWNSTREAM */
@@ -101,37 +102,61 @@
   PRINT(0)("============= DOWNSTREAM:===============\n");
   /* first of all read the synchronizeable's data: */
-  ret = this->synchronizeables->readBytes((byte*)downBuffer);
+  dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
 
   /* send the received data to connectionMonitor */
-  this->connectionMonitor->processPacket((byte*)downBuffer, ret);
+  this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
 
-  ret = this->networkProtocol->createHeader((byte*)downBuffer, ret, DATA_STREAM_BUFFER_SIZE,
-                                            *(this->synchronizeables), 12);
+  dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
+      *(this->synchronizeables), 12/* some random number (no real id)*/);
 
   /* pass the data to the network socket */
-  ret = this->networkSocket->writeBytes((byte*)downBuffer, ret);
+  dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
   /* check if there was an error */
-  if( ret == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
+  if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
 
 
 
   /* UPSTREAM */
-  ret = 0;
+  dataLength = 0;
   PRINT(0)("============== UPSTREAM:================\n");
-  /* first of all read  data from networkSocket*/
-  ret = this->networkSocket->readBlock((byte*)upBuffer, 11/* this is very bad: hard coded packet sizes! */);
-  /* error checking: data read? */
-  if( ret != 11 /*PACKAGE_SIZE + sizeof(Header)*/) { PRINTF(0)("Error while reading data from the NetworkSocket. Skipping further work\n");}
-  else
+  /* first of all read the next Orxonox Network Header */
+
+  switch( this->state)
   {
-    /* send the received data to connectionMonitor */
-    this->connectionMonitor->processPacket((byte*)upBuffer, ret);
 
-    /* extract Header */
-    Header header = this->networkProtocol->extractHeader((byte*) upBuffer , ret);
+    case NET_REC_HEADER:
+      dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
+      if( dataLength == sizeof(Header))
+      {
+        this->packetHeader = this->networkProtocol->extractHeader((byte*) upBuffer , dataLength);
+        printf("NetworkStream::processData() - Got Header: Protocol %u, Version: %u, Sender: %u, Receiver: %u, Length: %u\n",
+               this->packetHeader.protocol, this->packetHeader.version, this->packetHeader.senderID,
+               this->packetHeader.receiverID, this->packetHeader.length);
+        /* FIXME: what if it was no this->packetHeader? catch? eg: the protocol identifier, receiver id*/
 
-    /* now pass the data to the sync object */
-    this->synchronizeables->writeBytes((byte*)upBuffer, header.length);
+        this->state = NET_REC_DATA;
+      }
+      break;
+
+    case NET_REC_DATA:
+      /* now read the data */
+      dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
+      /* check if the data is available and process it if so */
+      if( dataLength == this->packetHeader.length)
+      {
+        printf("NetworkStream::processData() - Got Data: \n");
+        /* send the received data to connectionMonitor */
+        this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
+        /* now pass the data to the sync object */
+        this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
+
+        this->state = NET_REC_HEADER;
+      }
+      break;
+
+    default:
+      break;
   }
 
+
 }
Index: /branches/network/src/lib/network/network_stream.h
===================================================================
--- /branches/network/src/lib/network/network_stream.h	(revision 5808)
+++ /branches/network/src/lib/network/network_stream.h	(revision 5809)
@@ -8,4 +8,5 @@
 
 #include "data_stream.h"
+#include "network_protocol.h"
 
 class Synchronizeable;
@@ -13,4 +14,14 @@
 class ConnectionMonitor;
 class NetworkProtocol;
+
+
+//<! The state of the NetworkStream
+typedef enum NetStat {
+  NET_REC_HEADER = 0,                          //!< Waiting for header
+  NET_REC_DATA,                                //!< Waiting for data
+
+  NUM_STATES                                   //!< Number of states
+};
+
 
 class NetworkStream : public DataStream
@@ -21,5 +32,4 @@
   NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
   NetworkStream(Synchronizeable& sync, unsigned int port, NodeType type);
-
   ~NetworkStream();
 
@@ -37,4 +47,6 @@
    NetworkSocket* networkSocket;
    int                    type;
+   int                    state;
+   Header                 packetHeader;
 };
 #endif /* _NETWORK_STREAM */
