public override void Disconnect()
        {
            // clean up the socket properly
            if (socket != null)
            {
                ProxySocket pSocket = socket;
                socket = null;

                try
                {
                    if (IsSocketConnected(pSocket))
                    {
                        pSocket.Shutdown(SocketShutdown.Both);
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    pSocket.Close();
                }

                // We don't need to call OnDisconnect here since EndReceiveCallback will be call automatically later on. (This is not valid if disconnected remotelly)
                // We need to call OnDisconnect after EndReceiveCallback if disconnected locally.
                // We call Disconnect() when OnDisconnected event fired.
            }
        }
Пример #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!bool_0)
     {
         if (disposing && client != null)
         {
             try
             {
                 networkStream_0.Close();
             }
             catch
             {
             }
             try
             {
                 proxySocket_0.Close();
                 client.Close();
             }
             catch
             {
             }
             arc4_0 = (arc4_1 = null);
         }
         bool_0 = true;
     }
 }
        /// <summary>
        /// Forcefully closes the socket.
        /// </summary>
        public void Close() {
            // get the socket.
            if (ProxySocket != null) {
                ProxySocket.Close();

                Dispose(true);
            }
        }
Пример #4
0
 private void method_6()
 {
     arc4_0 = (arc4_1 = null);
     if (proxySocket_0.Connected)
     {
         proxySocket_0.Close();
     }
 }
Пример #5
0
        void btnTestProxy_Click(object sender, System.EventArgs e)
        {
            if (txtProxyIpAddress.Text.Trim() == "")
            {
                MsgBox.Warning("Sorry,the IP address can't be empty");
                return;
            }
            if (this.txtProxyUserName.Text.Trim() == "")
            {
                MsgBox.Warning("Sorry,the user name can't be empty");
                return;
            }
            if (this.txtProxyPortNumber.Text.Trim() == "")
            {
                MsgBox.Warning("Sorry,the port number can't be empty");
                return;
            }

            using (var cursor = new WaitCursor())
            {
                using (ProxySocket socket = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    IPEndPoint          endPoint      = new IPEndPoint(IPAddress.Parse(txtIpAddress.Text), Convert.ToInt32(txtPortNumber.Text));
                    IPEndPoint          proxyEndPoint = new IPEndPoint(IPAddress.Parse(this.txtProxyIpAddress.Text), Convert.ToInt32(this.txtProxyPortNumber.Text));
                    ProxyTypes          proxyType     = (ProxyTypes)Enum.Parse(typeof(ProxyTypes), ddlProxyType.SelectedItem.ToString());
                    TcpConnectionParams Params        = new TcpConnectionParams(endPoint, proxyEndPoint, proxyType, txtProxyUserName.Text, txtProxyPassword.Text);
                    socket.ProxyEndPoint = Params.ProxyEndPoint;
                    socket.ProxyType     = Params.ProxyType;
                    socket.ProxyUser     = Params.ProxyUser;
                    socket.ProxyPass     = Params.ProxyPassword;

                    try
                    {
                        socket.Connect(Params.EndPoint);
                        MsgBox.Warning("Test successful");
                    }
                    catch
                    {
                        MsgBox.Warning("Sorry,test failed,please try again");
                    }
                    finally
                    {
                        try
                        {
                            socket.Shutdown(SocketShutdown.Both);
                            socket.Close();
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        ///   Closes the connection
        /// </summary>
        public override void Close()
        {
            if (!IsDisposed)
            {
                try
                {
                    Send(EndStream);
                }
                // TODO: empty try-catch bad, martial arts good
// ReSharper disable EmptyGeneralCatchClause
                catch
// ReSharper restore EmptyGeneralCatchClause
                {
                }
                finally
                {
                    if (tlsProceedEvent != null)
                    {
                        tlsProceedEvent.Set();
                        tlsProceedEvent = null;
                    }

                    if (networkStream != null)
                    {
                        networkStream.Dispose();
                        networkStream = null;
                    }

                    if (socket != null)
                    {
                        socket.Close();
                        socket = null;
                    }

                    if (inputBuffer != null)
                    {
                        inputBuffer.Dispose();
                        inputBuffer = null;
                    }

                    if (parser != null)
                    {
                        parser.Dispose();
                        parser = null;
                    }
                }

                base.Close();
            }
        }
        public void Process()
        {
            var localEndPoint  = (IPEndPoint)client.LocalEndPoint;
            var remoteEndPoint = (IPEndPoint)client.RemoteEndPoint;
            var connection     = connectionTracker[new Connection(ProtocolType.Tcp, localEndPoint, remoteEndPoint)].Mirror;

            if (connection != null)
            {
                var initialEndPoint   = connection.Source;
                var requestedEndPoint = connection.Destination;
                var tcpConnection     = connectionTracker.GetTCPConnection(initialEndPoint, requestedEndPoint);

                var logMessage = string.Format("{0}[{1}] {2} {{0}} connection to {3}",
                                               tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                                               tcpConnection != null ? tcpConnection.PID : 0,
                                               initialEndPoint, requestedEndPoint);
                try
                {
                    var proxy = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    configureProxySocket(proxy, requestedEndPoint);

                    debug.Log(1, logMessage + " via {1}", "requested", proxy.ProxyEndPoint);

                    proxy.Connect(requestedEndPoint);

                    SocketPump.Pump(client, proxy);

                    proxy.Close();
                    debug.Log(1, logMessage, "closing");
                }
                catch (Exception ex)
                {
                    debug.Log(1, logMessage + ": {1}", "failed", ex.Message);
                }

                connectionTracker.QueueForCleanUp(connection);
            }
            else
            {
                var tcpConnection = connectionTracker.GetTCPConnection(remoteEndPoint, localEndPoint);
                debug.Log(1, "{0}[{1}] {2} has no mapping",
                          tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                          tcpConnection != null ? tcpConnection.PID : 0,
                          remoteEndPoint);
                client.Send(Encoding.ASCII.GetBytes("No mapping\r\n"));
            }

            client.Close();
        }
Пример #8
0
        private void StopListening()
        {
            if (socketListener != null)
            {
                try
                {
                    socketListener.Close();
                }
                catch (Exception ex)
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, GetType().ToString() + " Error: " + ex.Message);
                }

                socketListener = null;
            }
        }
Пример #9
0
        private void Terminate(Exception exception)
        {
            _stream.Close();
            _socket.Disconnect(false);
            _socket.Close();

            this.Connected = false;

            if (OnDisconnect != null)
            {
                OnDisconnect?.Invoke(this, exception.Message);
            }
            else
            {
                throw new PlayerIOError(ErrorCode.InternalError, string.Concat(new[] { "Connection from ", _endpoint.Address, " was closed. ", ", message: ", exception.Message }));
            }
        }
Пример #10
0
 public void Dispose()
 {
     try
     {
         clientSocket.Shutdown(SocketShutdown.Both);
     }
     catch
     {
     }
     try
     {
         try
         {
             mySocketEventArgs_0.Completed -= method_1;
             mySocketEventArgs_0.SetBuffer(null, 0, 0);
             mySocketEventArgs_0.Dispose();
         }
         catch
         {
             if (mySocketEventArgs_0 != null)
             {
                 mySocketEventArgs_0.Dispose();
             }
         }
     }
     catch
     {
     }
     try
     {
         clientSocket.Close();
         list_0 = null;
         arc4_0 = (arc4_1 = null);
     }
     catch
     {
     }
     try
     {
         clientSocket.Dispose();
     }
     catch
     {
     }
 }
Пример #11
0
        public void Disconnect()
        {
            if (Socket == null)
            {
                return;
            }

            try
            {
                Socket.Disconnect(false);
                Socket.Close();
                Socket = null;
            }
            catch (ObjectDisposedException) {}
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            OnDisconnect(this, null);
        }
Пример #12
0
        public void Disconnect()
        {
            if (_socket == null)
            {
                return;
            }

            try
            {
                _socket.Disconnect(false);
                _socket.Close();
                _socket = null;
            }
            catch (ObjectDisposedException e) {}
            catch (Exception e)
            {
                Log.Warn("Error occurred while disconnecting from socket", e);
            }

            OnDisconnect(this, null);
        }
Пример #13
0
 protected virtual void Dispose(bool disposing)
 {
     if (!bool_1)
     {
         if (disposing)
         {
             try
             {
                 timer_0.Enabled = false;
                 timer_0.Stop();
                 timer_0.Dispose();
             }
             catch
             {
             }
             try
             {
                 timer_3.Enabled = false;
                 timer_3.Stop();
                 timer_3.Dispose();
             }
             catch
             {
             }
             try
             {
                 timer_1.Enabled = false;
                 timer_1.Stop();
                 timer_1.Dispose();
             }
             catch
             {
             }
             try
             {
                 timer_2.Enabled = false;
                 timer_2.Stop();
                 timer_2.Dispose();
             }
             catch
             {
             }
             try
             {
                 tcpClient_0.GetStream().Close();
             }
             catch
             {
             }
             try
             {
                 proxySocket_0.Close();
                 proxySocket_0.Dispose();
             }
             catch
             {
             }
             try
             {
                 tcpClient_0.Close();
             }
             catch
             {
             }
             arc4_0 = (arc4_1 = null);
         }
         bool_1 = true;
     }
 }