Exemplo n.º 1
0
        public void Start(IPEndPoint local, IPEndPoint remote)
        {
            _mainSocket.Bind(local);
            _mainSocket.Listen(10);

            while (frmMain.Form.ServerConnected)
            {
                try
                {
                    var source = _mainSocket.Accept();
                    this._destination = new TcpProxy(false);
                    _destinationState = new State(source, _destination._mainSocket);
                    _destination.Connect(remote, source);
                    source.BeginReceive(_destinationState.Buffer, 0, _destinationState.Buffer.Length, 0, OnDataReceive, _destinationState);
                } catch { }
            }
        }
Exemplo n.º 2
0
        public void Close(TcpProxy proxy, State state)
        {
            try
            {
                state.DestinationSocket.Close();
            }
            catch { }

            try
            {
                state.SourceSocket.Close();
            }
            catch { }

            try
            {
                proxy.Socket.Close();
            }
            catch { }
        }
Exemplo n.º 3
0
        private void btnStartListen_Click(object sender, EventArgs e)
        {
            try
            {
                if (_serverStarted)
                {
                    return;
                }

                _serverStarted = true;
                _tcpForwarder  = new TcpProxy(true);

                _listenerThread = new Thread(RunListener);
                _listenerThread.Start();

                this.btnStartListen.Enabled = false;
                this.btnStopListen.Enabled  = true;
                this.btnSendData.Enabled    = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }