コード例 #1
0
 public void Dispose()
 {
     if (transferContext != null)
     {
         transferContext.Dispose();
     }
 }
コード例 #2
0
        /// <summary>
        /// The CloseClient.
        /// </summary>
        /// <param name="card">The card<see cref="ICard{ITransferContext}"/>.</param>
        public void CloseClient(ICard <ITransferContext> card)
        {
            ITransferContext context = card.Value;

            if (context == null)
            {
                Echo(string.Format("Client {0} does not exist.", context.Id));
            }
            else
            {
                try
                {
                    if (context.Listener != null && context.Listener.Connected)
                    {
                        context.Listener.Shutdown(SocketShutdown.Both);
                        context.Listener.Close();
                    }
                }
                catch (SocketException sx)
                {
                    Echo(sx.Message);
                }
                finally
                {
                    ITransferContext contextRemoved = clients.Remove(context.Id);
                    contextRemoved.Dispose();
                    Echo(string.Format("Client disconnected with Id {0}", context.Id));
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// The ClearClients.
        /// </summary>
        public void ClearClients()
        {
            foreach (ITransferContext closeContext in clients.AsValues())
            {
                ITransferContext context = closeContext;

                if (context == null)
                {
                    throw new Exception("Client does not exist.");
                }

                try
                {
                    context.Listener.Shutdown(SocketShutdown.Both);
                    context.Listener.Close();
                }
                catch (SocketException sx)
                {
                    Echo(sx.Message);
                }
                finally
                {
                    context.Dispose();
                    Echo(string.Format("Client disconnected with Id {0}", context.Id));
                }
            }
            clients.Clear();
        }
コード例 #4
0
 private void Close()
 {
     try
     {
         if (!IsConnected())
         {
             context.Dispose();
             return;
         }
         if (socket != null && socket.Connected)
         {
             socket.Shutdown(SocketShutdown.Both);
             socket.Close();
         }
         context.Dispose();
     }
     catch (SocketException)
     {
         // 4U2DO
     }
 }
コード例 #5
0
 /// <summary>
 /// The Dispose.
 /// </summary>
 public void Dispose()
 {
     if (MyHeader != null)
     {
         MyHeader.Dispose();
     }
     if (mymessage != null)
     {
         mymessage.Dispose();
     }
     if (HeaderReceived != null)
     {
         HeaderReceived.Dispose();
     }
     if (MessageReceived != null)
     {
         MessageReceived.Dispose();
     }
     if (Context != null)
     {
         Context.Dispose();
     }
 }
コード例 #6
0
        /// <summary>
        /// The CloseListener.
        /// </summary>
        public void CloseListener()
        {
            foreach (ITransferContext closeContext in clients.AsValues())
            {
                ITransferContext context = closeContext;

                if (context == null)
                {
                    Echo(string.Format("Client  does not exist."));
                }
                else
                {
                    try
                    {
                        if (context.Listener != null && context.Listener.Connected)
                        {
                            context.Listener.Shutdown(SocketShutdown.Both);
                            context.Listener.Close();
                        }
                    }
                    catch (SocketException sx)
                    {
                        Echo(sx.Message);
                    }
                    finally
                    {
                        context.Dispose();
                        Echo(string.Format("Client disconnected with Id {0}", context.Id));
                    }
                }
            }
            clients.Clear();
            shutdown = true;
            connectingNotice.Set();
            GC.Collect();
        }