private void Send <T>(int tableId, T deserialized)
        {
            string tableIdString;

            if (tableId < 10)
            {
                tableIdString = "0" + tableId.ToString();
            }
            else
            {
                tableIdString = tableId.ToString();
            }

            //Console.WriteLine("TableID to sent: " + tableIdString);
            socket.Send(Encoding.UTF8.GetBytes(tableIdString));
            Thread.Sleep(50);

            var    serializer   = new SyncXMLSerializer <T>();
            string returnString = serializer.Serializer(deserialized);
            int    stringLength = returnString.Length;
            string stringBytes  = stringLength.ToString();

            for (int i = stringBytes.Length; i < 10; i++)
            {
                stringBytes = "0" + stringBytes;
            }

            socket.Send(Encoding.UTF8.GetBytes(stringBytes));
            //Console.WriteLine("stringByte sent: " + stringBytes);
            Thread.Sleep(50);
            socket.Send(Encoding.UTF8.GetBytes(returnString));
            Console.WriteLine("Table " + tableIdString + " returned");
        }
        private void Recieve()
        {
            SyncXMLSerializer <ShCustomers>          customerXmlSerializer           = new SyncXMLSerializer <ShCustomers>();
            SyncXMLSerializer <ShIngredient>         ingredientXmlSerializer         = new SyncXMLSerializer <ShIngredient>();
            SyncXMLSerializer <ShIngredientCategory> ingredientCategoryXmlSerializer = new SyncXMLSerializer <ShIngredientCategory>();
            SyncXMLSerializer <ShOrderItems>         orderItemXmlSerializer          = new SyncXMLSerializer <ShOrderItems>();
            SyncXMLSerializer <ShOrders>             orderXmlSerializer             = new SyncXMLSerializer <ShOrders>();
            SyncXMLSerializer <ShPackage>            packageXmlSerializer           = new SyncXMLSerializer <ShPackage>();
            SyncXMLSerializer <ShProductInfo>        productInfoXmlSerializer       = new SyncXMLSerializer <ShProductInfo>();
            SyncXMLSerializer <ShRecipe>             recipeXmlSerializer            = new SyncXMLSerializer <ShRecipe>();
            SyncXMLSerializer <ShRecipeIngredients>  recipeIngredientsXmlSerializer = new SyncXMLSerializer <ShRecipeIngredients>();
            SyncXMLSerializer <ShRule>           ruleXmlSerializer         = new SyncXMLSerializer <ShRule>();
            SyncXMLSerializer <ShRuleCategories> ruleCategoryXmlSerializer = new SyncXMLSerializer <ShRuleCategories>();
            SyncXMLSerializer <ShShape>          shapeXmlSerializer        = new SyncXMLSerializer <ShShape>();

            int    length         = 0;
            string recievedString = "";
            int    TableId        = 0;
            bool   wrongRecieving = false;

            buffer = new byte[2];

            while (TableId < 12.5)
            {
                length         = socket.Receive(buffer);
                recievedString = Encoding.ASCII.GetString(buffer, 0, length);
                //Console.WriteLine(recievedString);
                //Console.WriteLine(buffer.Length);

                if (buffer.Length == 2)
                {
                    buffer  = new byte[10];
                    TableId = int.Parse(recievedString);
                    //Console.WriteLine("TableID: "+TableId.ToString());
                    continue;
                }
                else if (buffer.Length == 10)
                {
                    if (recievedString[9] == '<')
                    {
                        wrongRecieving = true;
                        recievedString = recievedString.Remove(9);
                        //Console.WriteLine("Wrong Recieving: Edited: " + recievedString);
                    }

                    buffer = new byte[int.Parse(recievedString)];
                    continue;
                }

                if (wrongRecieving)
                {
                    recievedString = "<" + recievedString;
                    wrongRecieving = false;
                }

                switch (TableId)
                {
                case 1:         //Customer
                    customers.Add(customerXmlSerializer.Deserialize(recievedString));
                    break;

                case 2:         //Ingredient
                    ingredients.Add(ingredientXmlSerializer.Deserialize(recievedString));
                    break;

                case 3:         //Ingredient_Category
                    ingredientCategory.Add(ingredientCategoryXmlSerializer.Deserialize(recievedString));
                    break;

                case 4:         //Order_Items
                    orderItems.Add(orderItemXmlSerializer.Deserialize(recievedString));
                    break;

                case 5:         //Orders
                    orders.Add(orderXmlSerializer.Deserialize(recievedString));
                    break;

                case 6:         //Packages
                    packages.Add(packageXmlSerializer.Deserialize(recievedString));
                    break;

                case 7:         //Product_Info
                    productInfo.Add(productInfoXmlSerializer.Deserialize(recievedString));
                    break;

                case 8:         //Recipe
                    recipe.Add(recipeXmlSerializer.Deserialize(recievedString));
                    break;

                case 9:         //Recipe_Ingredients
                    recipeIngredients.Add(recipeIngredientsXmlSerializer.Deserialize(recievedString));
                    break;

                case 10:        //Rule
                    rule.Add(ruleXmlSerializer.Deserialize(recievedString));
                    break;

                case 11:        //Rule_Categories
                    ruleCategories.Add(ruleCategoryXmlSerializer.Deserialize(recievedString));
                    break;

                case 12:        //Shape
                    shape.Add(shapeXmlSerializer.Deserialize(recievedString));
                    break;

                default:
                    break;
                }

                buffer = new byte[2];
            }
        }