internal void PostPublicationOnServer(DPE_ClientPublicationDefinition PublicationDefinition)
            {
                //crates the publication definition into a P2PData to send to the server
                CustomHashTable varsToPublish = new CustomHashTable();
                string          variableName  = "";

                DPE_ServerDefs.PublicationVariableDataType variableDataType = default(DPE_ServerDefs.PublicationVariableDataType);
                string variableDataTypeAsString = "";

                IEnumerator enumm = PublicationDefinition.VariablesToPublishTable.GetEnumerator();

                while (enumm.MoveNext())
                {
                    variableName             = System.Convert.ToString(((DictionaryEntry)enumm.Current).Key);
                    variableDataType         = (DPE_ServerDefs.PublicationVariableDataType)(((DictionaryEntry)enumm.Current).Value);
                    variableDataTypeAsString = DPE_ServerDefs.Get_String_FromPublicationVariableDataType(variableDataType);
                    varsToPublish.Add(variableName, variableDataTypeAsString);
                }

                P2PData data = new P2PData(DPE_ServerDefs.DPE_CMD_CREATE_PUBLICATION, varsToPublish);

                data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATIONS_GROUP, PublicationDefinition.PublicationsGroup);
                data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_CLIENT_ID, this._STXDataSocketClient.ClientID);
                data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, PublicationDefinition.PublicationName);

                Services.P2PCommunicationsScheme.P2PPortClient p2pclient = default(Services.P2PCommunicationsScheme.P2PPortClient);
                try
                {
                    p2pclient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsPost_PortNumber);
                    p2pclient.Connect();

                    //sends the information to the server in order to create it
                    p2pclient.SendData(P2PDataSendMode.SyncrhonicalSend, data);

                    p2pclient.Dispose();

                    //it the publication was created in the server then ists definition is saved in the publications posted manager
                    //in order to allow it to re create ii if needed
                    this.AddPublicationDefinitionAfterCreation(PublicationDefinition);

                    string msg = "Publication \'" + PublicationDefinition.PublicationName + "\'    ->    POSTED succesfully.";
                    CustomEventLog.WriteEntry(EventLogEntryType.SuccessAudit, msg);
                }
                catch (Exception ex)
                {
                    try
                    {
                        this.RemovePublicationDefinition(PublicationDefinition);
                    }
                    catch (Exception)
                    {
                    }
                    string errMSg = "";
                    errMSg = "Error creating the publication \'" + PublicationDefinition.PublicationName + "\' : " + ex.Message;
                    throw (new Exception(errMSg));
                }
            }
            internal void ConnectoToPublication(DPE_PublicationConnectionHandler_Type connectionHandlerType, string publicationName, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode)
            {
                //*****************************************************************************
                //request to the server the connection parameters of the publication
                P2PDataRequest dataREquest = new P2PDataRequest(DPE_ServerDefs.DPE_CMD_PUBLICATION_SUBSCRIPTION_DATA);

                dataREquest.AddRequestParameter(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, publicationName);

                P2PData publicationPArams = null;
                string  msg = "";

                Services.P2PCommunicationsScheme.P2PPortClient publicationsInformationRetrieveP2PPortClient = null;
                int trialsCount = 0;


                publicationsInformationRetrieveP2PPortClient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsInformationRetrieve_PortNumber);
                publicationsInformationRetrieveP2PPortClient.Connect();


                //performs a  while cycle until the client gets the connection parameters
                while (true)
                {
                    try
                    {
                        publicationPArams = publicationsInformationRetrieveP2PPortClient.RetrieveData(dataREquest);
                        break;
                    }
                    catch (Exception ex)
                    {
                        trialsCount++;

                        if (trialsCount >= MAX_DATA_CONNECTION_PARAMETERS_INQUIRY_TRIALS)
                        {
                            msg = "Error trying to connect to publication \'" + publicationName + "\': " + ex.Message;
                            throw (new Exception(msg));
                        }
                    }

                    System.Threading.Thread.Sleep(10);
                }

                try
                {
                    publicationsInformationRetrieveP2PPortClient.Dispose();
                }
                catch (Exception)
                {
                }

                CustomHashTable paramsList          = (CustomHashTable)publicationPArams.Value;
                string          publicationHostNAme = System.Convert.ToString(paramsList.Item(DPE_PublicationsDefinitions.DPE_PUBLICATION_HOSTNAME));
                int             publicationPort     = System.Convert.ToInt32(paramsList.Item(DPE_PublicationsDefinitions.DPE_PUBLICATION_PORT));

                //*****************************************************************************
                //CREATION OF THE PUBLICATION HANDLER and CONNECTION WITH publication
                DPE_PublicationConnectionHandler publicationConnectionHandler = default(DPE_PublicationConnectionHandler);

                publicationConnectionHandler = this.CreatePublicationConnectionHandler(connectionHandlerType, this._STXDataSocketClient, publicationName, publicationHostNAme, publicationPort, connectionMode);


                //*****************************************************************************
                //Ciclic process in order to allow the server to register the client socket connection . -> to synchronize the client registration
                //by ser client with the server event to log the publication event

                msg = "Error trying to perform the client connection registration to the publication \'" + publicationName + "\' : ";

                //*****************************************************************************
                //registration of the client connection to a publication in the server
                //the client sends to the server a information telling to which publication has already connected
                //and also for the TCP client mode to tell the publication to which port send the data

                int  connectionRegistrationTrialCounter = 0;
                bool connectionRegistration             = false;

                //preparation of the connection information into a p2p data
                P2PData clientPubCnnData = new P2PData(DPE_ServerDefs.DPE_CMD_CLIENT_PUBLICATION_CONNECTION_REGISTRATION, DPE_ServerDefs.DPE_CMD_CLIENT_PUBLICATION_CONNECTION_REGISTRATION);

                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_CLIENT_ID, this._STXDataSocketClient.ClientID);
                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, publicationName);
                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_CONNECTION_HANDLER_ID, publicationConnectionHandler.HandlerID);
                //---------------------HANDLING FOR THE CONNECTION MODE ------------------------------
                string connectionModeAsString = "";

                connectionModeAsString = DPE_ServerDefs.Get_STXDSS_PublicationConnectionMode_ToAString(connectionMode);
                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_CLIENT_CONNECTION_MODE, connectionModeAsString);


                msg = "Error trying to perform the client connection registration to the publication \'" + publicationName + "\' : ";


                //sends to server the information to the server several times until the information reaches the server
                Services.P2PCommunicationsScheme.P2PPortClient publicationsClientRegistrationP2PPortClient = default(Services.P2PCommunicationsScheme.P2PPortClient);

                publicationsClientRegistrationP2PPortClient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsClientRegistration_PortNumber);
                publicationsClientRegistrationP2PPortClient.Connect();

                while (connectionRegistration == false)
                {
                    try
                    {
                        publicationsClientRegistrationP2PPortClient.SendData(P2PDataSendMode.SyncrhonicalSend, clientPubCnnData);

                        connectionRegistration = true;

                        publicationsClientRegistrationP2PPortClient.Dispose();

                        CustomEventLog.WriteEntry(EventLogEntryType.SuccessAudit, "Connection to publication \'" + publicationName + "\' succesfull");

                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Threading.Thread.Sleep(10);

                        connectionRegistrationTrialCounter++;

                        if (connectionRegistrationTrialCounter >= MAX_CONNECTION_REGISTRATION_TRIALS)
                        {
                            msg = msg + ex.Message;

                            try
                            {
                                publicationsClientRegistrationP2PPortClient.Dispose();
                            }
                            catch (Exception)
                            {
                            }

                            try
                            {
                                this.DisposeConnectionHandler(publicationName);
                            }
                            catch (Exception)
                            {
                            }

                            throw (new Exception(msg));
                        }
                    }
                }
            }