示例#1
0
            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)
                {
                }
            }
示例#2
0
            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;
            }