Exemplo n.º 1
0
        private async Task ListenConnection()
        {
            while (flagStopServer == 0)
            {
                try
                {
                    var client = await tcpListener.AcceptTcpClientAsync();

                    IPEndPoint ipEndPoint;
                    do
                    {
                        ipEndPoint = TargetServer();
                        try
                        {
                            var connect = new TcpProxyConnection(client, ClosedProxyConnection, ipEndPoint);
                            TargetIncrease(ipEndPoint);
                            break;
                        }
                        catch (SocketException e)
                        {
                            lock (countConnectionTarget)
                            {
                                var t = countConnectionTarget[ipEndPoint];
                                t.Enable = false;
                                countConnectionTarget[ipEndPoint] = t;
                            }
                            break;
                        }
                    } while (ipEndPoint != null);
                }
                catch (SocketException)
                {
                }
            }
        }
Exemplo n.º 2
0
 private void ClosedProxyConnection(TcpProxyConnection tcpConnect, IPEndPoint target)
 {
     TargetDecrease(target);
     tcpConnect.Dispose();
     Console.WriteLine($"Client disconnected form {target}, count connection target {countConnectionTarget[target].CountConnection}");
 }