public frmSocketsServerClientTest(string host, int port) { // This call is required by the Windows Form Designer. InitializeComponent(); try { // Add any initialization after the InitializeComponent() call. this._dataSocketClient = new SocketsServerClient(host, port); this._dataSocketClient.DataReceived += this.DataReceived; this._dataSocketClient.ConnectionLost += this.Disconnection; this._dataSocketClient.Connect(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { this._stxEventLog = CustomEventLog.GetInstance(); this._stxEventLog.LogEntryReceived += this._stxEventLog_LogEntryReceived; } catch (Exception ex) { MessageBox.Show(ex.Message); } try { this.Text = "Sockets Server Client on : " + host + " : " + System.Convert.ToString(port); } catch (Exception) { } }
private void DataReceived(SocketData Data, SocketsServerClient sender) { try { this._dataCount++; this.SetTextBoxText(this.txtDataReceivedCount, System.Convert.ToString(this._dataCount)); if (this.chkshowIncommingData.Checked) { this.SetListBoxItem(this.lstServerData, Data); string logStr = DateTime.Now.ToString() + "-> " + Data.XMLDataString; this.SetListBoxItem(this.lstReceptionLog, logStr); //displays the attributes list ListBox_Items_Clear(this.lstDataAttributes); UtilitiesLibrary.Parametrization.Attribute attr = default(UtilitiesLibrary.Parametrization.Attribute); IEnumerator enumm = Data.AttributesTable.GetEnumerator(); string attrString = ""; while (enumm.MoveNext()) { attr = (UtilitiesLibrary.Parametrization.Attribute)enumm.Current; attrString = attr.Name + " - " + attr.Value; ListBox_Items_Add(this.lstDataAttributes, attrString); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void _client_ConnectionLost(SocketsServerClient sender) { if (ConnectionLost != null) { ConnectionLost(this); } }
private void TCPSocketsServerClient_ConnectionLost(CommunicationsLibrary.Services.SocketsDataDistribution.SocketsServerClient sender) { try { //adds to the table of clients which connection went lost in order to further evaluate if //a local client is valid to send data lock (this._DisconnectedTCPsocketServerClientsTable) { this._DisconnectedTCPsocketServerClientsTable.Add(sender.ClientID, sender); } string clientID = sender.ClientID; //removes any event hanlder for the connection object SocketsServerClient client = null; if (this._TCPSocketsServerClientsTable.ContainsKey(clientID)) { client = (SocketsServerClient)this._TCPSocketsServerClientsTable[sender.ClientID]; client.ConnectionLost -= TCPSocketsServerClient_ConnectionLost; } this.CleanClientDisconnectionsEnvironment(); //gets the connection string id and removes from the connections available string connectionPortStringID = ""; int portNumber = Convert.ToInt32(sender.ServerListeningPort); connectionPortStringID = this.GetConnectionStringID(sender.ServerHostName, portNumber); lock (this._TCPSocketsConnectionStringIDReferenceTable) { this._TCPSocketsConnectionStringIDReferenceTable.Remove(connectionPortStringID); } if (!(client == null)) { try { client.DisconnectFromServer(); } catch (Exception) { } try { client.Dispose(); } catch (Exception) { } } } catch (Exception) { } }
public DPE_PublicationConnectionHandler(DPE_PublicationConnectionHandler_Type handlerType, DPE_DataPublicationsClient client, string PublicationName, string PublicationHostName, int publicationsSocketsServerPortNumber, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { //************************************************************************************* this._STXDSSC_PublicationsProxyConnectionsServerClient = DPE_PublicationsConnectionsProxyServerClient.GetInstance(client.PublicationsMainServerDataBaseConnectionString); this._STXDSSC_PublicationsProxyConnectionsServerClient.ConnectionWithProxyServerLost += this._STXDSSC_PublicationsProxyConnectionsServerClient_ConnectionWithProxyServerLost; this._STXDSSC_PublicationsProxyConnectionsServerClient.Connect(); this._handlerType = handlerType; this._STXDataSocketClient = client; this._publicationName = PublicationName; this._publicationHostNAme = PublicationHostName; this._publicationPort = publicationsSocketsServerPortNumber; this._connectionMode = connectionMode; //************************************************************************************* //creates the server socket client to the publication's socket server in order to use it as endpoint to detect //when the publication goes off line string clientName = this._publicationName + Guid.NewGuid().ToString(); this._PublicationSocketsServerClient = new SocketsServerClient(clientName, this._publicationHostNAme, this._publicationPort); this._PublicationSocketsServerClient.DataReceived += publicationSocketClient_DataReceived; this._PublicationSocketsServerClient.ConnectionLost += publicationSocketClient_ConnectionLost; this._PublicationSocketsServerClient.Connect(); //becuase only the subscriptors clients will receive data from the publication if (handlerType == DPE_PublicationConnectionHandler_Type.subscriptorHandler) { //***************************************************************************************** try { //asks the proxy server to have a handle to create a sql reader to read locally the publications update this._DSSPublicationsSQLReader = this._STXDSSC_PublicationsProxyConnectionsServerClient.GetPublicationSocketsServerListenerClient(this._publicationName, this._publicationHostNAme); this._DSSPublicationsSQLReader.dataResetFromPublication += EventHandling_DSSPublicationsSQLReader_dataResetFromPublication; this._DSSPublicationsSQLReader.dataUpdateFromPublication += EventHandling_DSSPublicationsSQLReader_dataUpdateFromPublication; this._DSSPublicationsSQLReader.StartReading(); this._STXDSSC_PublicationsProxyConnectionsServerClient.LogClientConnectionFromPublication(this._STXDSSC_PublicationsProxyConnectionsServerClient.SocketsServerClientID, this._STXDataSocketClient, this._publicationName); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } else if (handlerType == DPE_PublicationConnectionHandler_Type.publisherHandler) { this._DSSPublicationsSQLWriter = new DPE_PublicationsSQLWriter(client.PublicationsMainServerDataBaseConnectionString, this._publicationName); } }
private void _client_DataReceived(SocketData Data, SocketsServerClient sender) { //event received from ALDS data server through the sockets server ALDSData ALDSdata; Boolean result = this.TryParse(Data, out ALDSdata); if (result) { if (DataReceived != null) { DataReceived(this, ALDSdata); } } }
private void publicationSocketClient_ConnectionLost(SocketsServerClient sender) { if (this._handlerType == DPE_PublicationConnectionHandler_Type.subscriptorHandler) { try { if (ConnectionToPublicationLostEvent != null) { ConnectionToPublicationLostEvent(this._publicationName); } } catch (Exception) { } } }
private void publicationSocketClient_DataReceived(SocketData data, SocketsServerClient sender) { try { //data received from the publication to this specific client //the data incomming from this is intended to be recived as when the client connects to the publication //and receives the current publication data to this point //******************************************************* this.ProcessPublicationUpdateDataReceivedOnConnection(data); //******************************************************* } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } }
internal void HandleUnicastTCPConnectionToRemoteProxy(string HostName, int listeningTCPPortNumber) { //creates a unique string ID using the hostname and the port number in order to determine it there //is a previous connection to that port string connectionPortStringID = ""; connectionPortStringID = this.GetConnectionStringID(HostName, listeningTCPPortNumber); if (!this._TCPSocketsConnectionStringIDReferenceTable.Contains(connectionPortStringID)) { SocketsServerClient socketsServerClient = new SocketsServerClient(HostName, listeningTCPPortNumber); socketsServerClient.Connect(); socketsServerClient.ConnectionLost += TCPSocketsServerClient_ConnectionLost; //----------------------------------------------------------------- //adds to the socketsServerClients Table that hold the connection handlers lock (this._TCPSocketsServerClientsTable) { try { this._TCPSocketsServerClientsTable.Remove(socketsServerClient.ClientID); } catch (Exception) { } this._TCPSocketsServerClientsTable.Add(socketsServerClient.ClientID, socketsServerClient); } //----------------------------------------------------------------- //adds to the reference connectionsStringID in order to know that a connection to the //specified host and port exists already lock (this._TCPSocketsConnectionStringIDReferenceTable) { try { this._TCPSocketsConnectionStringIDReferenceTable.Remove(connectionPortStringID); } catch (Exception) { } this._TCPSocketsConnectionStringIDReferenceTable.Add(connectionPortStringID, socketsServerClient); } } }
private bool disposedValue = false; // To detect redundant calls // IDisposable protected virtual void Dispose(bool disposing) { if (!this.disposedValue) { if (disposing) { // TODO: free other state (managed objects). try { this._dataDistributionTimer.Stop(); this._dataDistributionTimer.Dispose(); } catch (Exception) { } IEnumerator enumm = default(IEnumerator); SocketsServerClient client = default(SocketsServerClient); enumm = this._TCPSocketsServerClientsTable.GetEnumerator(); while (enumm.MoveNext()) { client = (SocketsServerClient)(((DictionaryEntry)enumm.Current).Value); try { client.DisconnectFromServer(); client.Dispose(); } catch (Exception) { } } } // TODO: free your own state (unmanaged objects). // TODO: set large fields to null. } this.disposedValue = true; }
private void CleanClientDisconnectionsEnvironment() { //removes from the sockets clients table the ones which disconnection went lost //in order to avoid to try to send data to a connection that is no longer valid if (this._DisconnectedTCPsocketServerClientsTable.Count > 0) { SocketsServerClient client = null; lock (this._DisconnectedTCPsocketServerClientsTable) { IEnumerator enumm = default(IEnumerator); enumm = this._DisconnectedTCPsocketServerClientsTable.GetEnumerator(); while (enumm.MoveNext()) { client = (SocketsServerClient)(((DictionaryEntry)enumm.Current).Value); lock (this._TCPSocketsServerClientsTable) { try { this._TCPSocketsServerClientsTable.Remove(client.ClientID); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } } try { this._DisconnectedTCPsocketServerClientsTable.Clear(); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } }
private void eventHandling__dataDistributionTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { this._dataDistributionTimer.Stop(); SocketData dataToBeSend = null; if (this._TCPUnicastDataDistributionQueue.Count > 0) { lock (this._TCPUnicastDataDistributionQueue) { try { dataToBeSend = (SocketData)this._TCPUnicastDataDistributionQueue.Dequeue(); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); dataToBeSend = null; } } if (!(dataToBeSend == null)) { IEnumerator enumm = default(IEnumerator); SocketsServerClient client = default(SocketsServerClient); lock (this._TCPSocketsServerClientsTable) { try { enumm = this._TCPSocketsServerClientsTable.GetEnumerator(); while (enumm.MoveNext()) { try { client = (SocketsServerClient)(((DictionaryEntry)enumm.Current).Value); //verifies if the client is valid to send data if (!this._DisconnectedTCPsocketServerClientsTable.ContainsKey(client.ClientID)) { try { client.SendDataToServer(dataToBeSend); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } Thread.Sleep(1); } } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } finally { if (this._TCPUnicastDataDistributionQueue.Count > 0) { this._dataDistributionTimer.Start(); } } }
public ALDSDataClient(string hostName) { this._client = new SocketsServerClient(hostName, ALDSDataServerLibrary.Server.ALDSDataServer.ALDS_DATA_SERVER_PORT); this._client.ConnectionLost += new SocketsServerClient.ConnectionLostEventHandler(_client_ConnectionLost); this._client.DataReceived += new SocketsServerClient.DataReceivedEventHandler(_client_DataReceived); }