private void AcceptInboundCallback(IAsyncResult ar) { TcpClient inbound; try { inbound = listener.EndAcceptTcpClient(ar); } catch (Exception e) { if(e is NullReferenceException || e is ObjectDisposedException) return; Stop(); throw; } var proxy = new TcpProxy(inbound, outboundHost, outboundPort, inboundToOutboundDelay, outboundToInboundDelay, bufferSize); proxy.Connect(); proxy.Closed += ProxyClosed; AddProxy(proxy); listener.BeginAcceptTcpClient(AcceptInboundCallback, listener); }
public TcpProxyViewModel(TcpProxy tcpProxy) { dispatcher = Dispatcher.CurrentDispatcher; this.tcpProxy = tcpProxy; Status = TcpProxyStatus.Running; RemoteEndpoint = tcpProxy.RemoteEndpoint.ToString(); tcpProxy.InboundReadChanged += i => InboundRead = i; tcpProxy.OutboundReadChanged += i => OutboundRead = i; tcpProxy.OutboundWrittenChanged += i => OutboundWritten = i; tcpProxy.InboundWrittenChanged += i => InboundWritten = i; tcpProxy.Closed += TcpProxyOnClosed; }
private void TcpServerOnProxyRemoved(TcpProxy tcpProxy) { ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(5000); dispatcher.Invoke(new Action<TcpProxy>(RemoveProxy), tcpProxy); }); }
private void TcpServerOnProxyAdded(TcpProxy tcpProxy) { dispatcher.Invoke(new Action<TcpProxy>(AddProxy), tcpProxy); }
private void RemoveProxy(TcpProxy proxy) { var toRemove = Proxies.SingleOrDefault(p => p.UnderlyingProxy == proxy); if (toRemove != null) Proxies.Remove(toRemove); }
private void AddProxy(TcpProxy proxy) { Proxies.Add(new TcpProxyViewModel(proxy)); }
private void ProxyClosed(TcpProxy proxy) { if (proxies.Remove(proxy)) ProxyRemoved(proxy); }
private void AddProxy(TcpProxy proxy) { proxies.Add(proxy); ProxyAdded(proxy); }
private void TcpProxyOnClosed(TcpProxy _) { dispatcher.Invoke(new Action(() => { Status = TcpProxyStatus.Stopped; })); }