Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;

            // SSL server address
            string address = "127.0.0.1";

            if (args.Length > 0)
            {
                address = args[0];
            }

            // SSL server port
            int port = 2222;

            if (args.Length > 1)
            {
                port = int.Parse(args[1]);
            }

            Console.WriteLine($"SSL server address: {address}");
            Console.WriteLine($"SSL server port: {port}");

            Console.WriteLine();

            // Create and prepare a new SSL client context
            var context = new SslContext(SslProtocols.Tls12, new X509Certificate2(@"C:\Users\user\Downloads\client.pfx", "qwerty"), (sender, certificate, chain, sslPolicyErrors) => true);

            // Create a new SSL client
            var client = new SocketClient(context, address, port);

            // Connect the client
            Console.Write("Client connecting...");
            client.ConnectAsync();
            Console.WriteLine("Done!");

            Console.WriteLine("Press Enter to stop the client or '!' to reconnect the client...");

            // Perform text input
            do
            {
                string line = GenerateRandomData();

                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                // Disconnect the client
                if (line == "!")
                {
                    Console.Write("Client disconnecting...");
                    client.DisconnectAsync();
                    Console.WriteLine("Done!");
                    continue;
                }

                // Map client data to a model
                var separatedData = line.Split(';');

                var dataModel = new DataModel(
                    firstName: separatedData[0],
                    lastName: separatedData[1],
                    city: separatedData[2],
                    postCode: separatedData[3],
                    appVersion: separatedData[4],
                    email: separatedData[5],
                    music: separatedData[6],
                    performer: separatedData[7],
                    year: int.Parse(separatedData[8]),
                    hour: int.Parse(separatedData[9]),
                    md5Hash: separatedData[10],
                    fileName: separatedData[11],
                    fileType: separatedData[12],
                    date: DateTime.Parse(separatedData[13]));

                // Send the client data
                client.SendAsync(dataModel);
            }while (true);

            // Disconnect the client
            Console.Write("Client disconnecting...");
            client.DisconnectAndStop();
            Console.WriteLine("Done!");
        }