Custom TCP hanlder to allow HTTP proxy auth

This commit is contained in:
Starli0n 2017-01-27 10:58:47 +01:00
parent 85c206cc24
commit 48077961ae
2 changed files with 18 additions and 9 deletions

View file

@ -1,22 +1,28 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace TLSharp.Core.Network
{
public delegate TcpClient TcpClientConnectionHandler(string address, int port);
public class TcpTransport : IDisposable
{
private readonly TcpClient _tcpClient;
private int sendCounter = 0;
public TcpTransport(string address, int port)
public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null)
{
_tcpClient = new TcpClient();
if (handler == null)
{
_tcpClient = new TcpClient();
var ipAddress = IPAddress.Parse(address);
_tcpClient.Connect(ipAddress, port);
var ipAddress = IPAddress.Parse(address);
_tcpClient.Connect(ipAddress, port);
}
else
_tcpClient = handler(address, port);
}
public async Task Send(byte[] packet)
@ -84,6 +90,6 @@ namespace TLSharp.Core.Network
{
if (_tcpClient.Connected)
_tcpClient.Close();
}
}
}
}