public override void Update()
 {
     while (true)
     {
         if (currentpacketsize == 0)
         {
             //read new packetype
             if (ReceiveBuffer.Length < 2) return; //there is no data available so we cant read any
             currentpacketsize = BitConverter.ToUInt16(ReceiveBuffer.Read(2), 0);
         }
         if (currentpacketsize != 0)
         {
             if (ReceiveBuffer.Length >= currentpacketsize)
             {
                 byte[] buffer = ReceiveBuffer.Read(currentpacketsize);
                 ByteStream packet = new ByteStream(buffer);
                 bool broadcast = packet.Read() != 0;
                 uint action = (uint)Converter.Read(packet);
                 if (!NetworkManager.ActionBlackList.Contains(action))
                 {
                     NetworkManager.ActionBlackList.Add(action);
                     if (broadcast)
                     {
                         foreach (Connection c in NetworkManager.LocalNode.Connections)
                         {
                             if (c != this) c.Send(new ByteStream(buffer));
                         }
                     }
                     methods.ExecuteCommand(packet);
                 }
                 currentpacketsize = 0;
             }
             else return;
         }
     }
 }
 internal virtual void ExecuteCommand(ByteStream _Stream)
 {
     byte command = _Stream.Read();
     switch (command)
     {
         case 1://invoke method
             {
                 string methodname = (string)Converter.Read(_Stream);
                 MethodInfo info = GetNetworkMethodInfo(methodname);
                 if (info != null)
                 {
                     int paramcount = (ushort)Converter.Read(_Stream);
                     object[] parameters = new object[paramcount];
                     for (int i = 0; i < paramcount; i++)
                         parameters[i] = Converter.Read(_Stream);
                     InvokeMethod(methodname, parameters);
                 }
                 else Log.Write("NetworkClass", Log.Line.Type.Error, "Cant find method with name {0}", methodname);
             }
             break;
         case 2://set field
             {
                 string fieldname = (string)Converter.Read(_Stream);
                 FieldInfo info = GetNetworkFieldInfo(fieldname);
                 if (info != null)
                 {
                     object value = Converter.Read(_Stream);
                     SetField(fieldname, value);
                 }
                 else Log.Write("NetworkClass", Log.Line.Type.Error, "Cant find field with name {0}", fieldname);
             }
             break;
     }
 }