public static async Task TcpConnect(BotData data, string host, int port, bool useSSL, int timeoutMilliseconds = 10000) { data.Logger.LogHeader(); var tcpClient = await TcpClientFactory.GetClientAsync(host, port, TimeSpan.FromMilliseconds(timeoutMilliseconds), data.UseProxy?data.Proxy : null, data.CancellationToken) .ConfigureAwait(false); var netStream = tcpClient.GetStream(); data.SetObject("netStream", netStream); if (useSSL) { var sslStream = new SslStream(netStream); await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { TargetHost = host, }, data.CancellationToken).ConfigureAwait(false); data.SetObject("sslStream", sslStream); } data.Logger.Log($"The client connected to {host} on port {port}", LogColors.Mauve); }
public void CreateTcpClientTest() { var factory = new TcpClientFactory(); Assert.Throws <ArgumentNullException>(() => factory.CreateTcpClient(null, TcpClientType.SOCKS4)); factory.ProxyAddress = new SocketAddress("127.0.0.1", 80); Assert.ThrowsAny <SocketException>(() => factory.CreateTcpClient(new SocketAddress("www.gooogle.it", 80), TcpClientType.SOCKS4)); Assert.ThrowsAny <SocketException>(() => factory.CreateTcpClient(new SocketAddress("www.gooogle.it", 80), TcpClientType.SOCKS4a)); Assert.ThrowsAny <SocketException>(() => factory.CreateTcpClient(new SocketAddress("www.gooogle.it", 80), TcpClientType.SOCKS5)); Assert.ThrowsAny <ArgumentNullException>(() => factory.CreateTcpClient(null, TcpClientType.SOCKS4)); Assert.ThrowsAny <ArgumentNullException>(() => factory.CreateTcpClient(null, TcpClientType.SOCKS4a)); Assert.ThrowsAny <ArgumentNullException>(() => factory.CreateTcpClient(null, TcpClientType.SOCKS5)); /// TO DECOMMENT FOR TESTING /// //factory.ProxyAddress = new SocketAddress("address", port); //Assert.ThrowsAny<SocksException>(() => factory.CreateTcpClient(new SocketAddress("host", port), TcpClientType.SOCKS4)); //Assert.ThrowsAny<SocksException>(() => factory.CreateTcpClient(new SocketAddress("host", port), TcpClientType.SOCKS4a)); //Assert.ThrowsAny<SocksException>(() => factory.CreateTcpClient(new SocketAddress("host", port), TcpClientType.SOCKS5)); //factory.CreateTcpClient(new SocketAddress("tcpaddress", port), TcpClientType.SOCKS5); //factory.ProxyAddress = new SocketAddress("address", port); //factory.CreateTcpClient(new SocketAddress("tcpaddress", port), TcpClientType.SOCKS4); }
public async Task <(BinaryObjectPipeReader, BinaryObjectPipeWriter)> Connect() { var addr = await client.Connect(); var networkStream = (await TcpClientFactory.CreateTcpClient(addr)).GetStream(); return(new BinaryObjectPipeReader(networkStream, dictionary), new BinaryObjectPipeWriter(networkStream, dictionary)); }
public async Task ConnectTcp() { await using var iterator = server.MonitorForConnection().GetAsyncEnumerator(); var task = iterator.MoveNextAsync(); using var client = await TcpClientFactory.CreateTcpClient(server.AddressArray()); Assert.True(await task); Assert.NotNull(iterator.Current); }
private DefaultProxy createProxy() { var dialog = new DefaultProxyDialog(); dialog.ShowDialog(); if (dialog.DialogResult == DialogResult.OK) { var clFactory = new TcpClientFactory(dialog.TcpClientFactorySettings); var srv = new TcpServer(dialog.TcpServerSettings); return(new DefaultProxy(new DefaultProxySettings { Server = srv, ClientFactory = clFactory })); } return(null); }