Beispiel #1
0
 ///<summary>Disposes of the resources (other than memory) used by the Client.</summary>
 ///<remarks>Closes the connections with the local client and the remote host. Once <c>Dispose</c> has been called, this object should not be used anymore.</remarks>
 ///<seealso cref ="System.IDisposable"/>
 public void Dispose()
 {
     try {
         ClientSocket.Shutdown(SocketShutdown.Both);
     } catch {}
     try {
         DestinationSocket.Shutdown(SocketShutdown.Both);
     } catch {}
     //Close the sockets
     if (ClientSocket != null)
     {
         ClientSocket.Close();
     }
     if (DestinationSocket != null)
     {
         DestinationSocket.Close();
     }
     //Clean up
     ClientSocket      = null;
     DestinationSocket = null;
     if (Destroyer != null)
     {
         Destroyer(this);
     }
 }
Beispiel #2
0
 public void Dispose()
 {
     try
     {
         if (ClientSocket != null)
         {
             ClientSocket.Shutdown(SocketShutdown.Both);
         }
     }
     catch
     {
     }
     try
     {
         if (DestinationSocket != null)
         {
             DestinationSocket.Shutdown(SocketShutdown.Both);
         }
     }
     catch
     {
     }
     ClientSocket?.Close();
     DestinationSocket?.Close();
     ClientSocket      = null;
     DestinationSocket = null;
     _destroyer?.Invoke(this);
 }
 ///<summary>Connects to the specified endpoint.</summary>
 ///<param name="RemoteServer">The IPEndPoint to connect to.</param>
 ///<exception cref="SocketException">There was an error connecting to the specified endpoint</exception>
 private void ConnectTo(IPEndPoint RemoteServer)
 {
     if (DestinationSocket != null)
     {
         try
         {
             DestinationSocket.Shutdown(SocketShutdown.Both);
         }
         catch
         {
         }
         finally
         {
             DestinationSocket.Close();
         }
     }
     try
     {
         DestinationSocket = new Socket(RemoteServer.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         DestinationSocket.BeginConnect(RemoteServer, OnRemoteConnected, DestinationSocket);
     }
     catch
     {
         throw new SocketException();
     }
 }
Beispiel #4
0
 ///<summary>Disposes of the resources (other than memory) used by the Client.</summary>
 ///<remarks>Closes the connections with the local client and the remote host. Once <c>Dispose</c> has been called, this object should not be used anymore.</remarks>
 ///<seealso cref ="System.IDisposable"/>
 public void Dispose()
 {
     try
     {
         ClientSocket.Shutdown(SocketShutdown.Both);
     }
     catch { }
     try
     {
         DestinationSocket.Shutdown(SocketShutdown.Both);
     }
     catch { }
     //Close the sockets
     if (ClientSocket != null)
     {
         ClientSocket.Close();
     }
     if (DestinationSocket != null)
     {
         DestinationSocket.Close();
     }
     //Clean up
     CompleteSendBuffer = string.Empty;
     CompleteReadBuffer = string.Empty;
     ClientSocket       = null;
     DestinationSocket  = null;
     if (Destroyer != null)
     {
         Destroyer(this);
     }
 }
Beispiel #5
0
        ///<summary>Disposes of the resources (other than memory) used by the Client.</summary>
        ///<remarks>Closes the connections with the local client and the remote host. Once <c>Dispose</c> has been called, this object should not be used anymore.</remarks>
        ///<seealso cref ="System.IDisposable"/>
        public void Dispose()
        {
            try
            {
                lock (_bufferLock)
                {
                    lock (_disposeLock)
                    {
                        try
                        {
                            ClientSocket.Shutdown(SocketShutdown.Both);
                        }
                        catch
                        {
                        }
                        if (ClientSocket != null)
                        {
                            ClientSocket.Close();
                        }

                        try
                        {
                            DestinationSocket.Shutdown(SocketShutdown.Both);
                        }
                        catch
                        {
                        }
                        if (DestinationSocket != null)
                        {
                            DestinationSocket.Close();
                        }

                        ClientSocket      = null;
                        DestinationSocket = null;

                        if (Destroyer != null)
                        {
                            Destroyer(this);
                        }
                    }
                }
            }
            catch
            {
            }
        }
Beispiel #6
0
 public void Dispose()
 {
     try
     {
         if (ClientSocket != null)
         {
             ClientSocket.Shutdown(SocketShutdown.Both);
         }
     }
     catch
     {
     }
     try
     {
         if (DestinationSocket != null)
         {
             DestinationSocket.Shutdown(SocketShutdown.Both);
         }
     }
     catch
     {
     }
     if (ClientSocket != null)
     {
         ClientSocket.Close();
     }
     if (DestinationSocket != null)
     {
         DestinationSocket.Close();
     }
     ClientSocket      = null;
     DestinationSocket = null;
     if (_destroyer != null)
     {
         _destroyer(this);
     }
 }