示例#1
0
 /// <summary>
 /// Initialize SSL server with a given IP endpoint
 /// </summary>
 /// <param name="context">SSL context</param>
 /// <param name="endpoint">IP endpoint</param>
 public SslServer(SslContext context, IPEndPoint endpoint)
 {
     Id       = Guid.NewGuid();
     Context  = context;
     Endpoint = endpoint;
 }
示例#2
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!");
        }
示例#3
0
 /// <summary>
 /// Initialize SSL server with a given IP address and port number
 /// </summary>
 /// <param name="context">SSL context</param>
 /// <param name="address">IP address</param>
 /// <param name="port">Port number</param>
 public SslServer(SslContext context, string address, int port) : this(context, new IPEndPoint(IPAddress.Parse(address), port))
 {
 }
示例#4
0
 /// <summary>
 /// Initialize SSL server with a given IP address and port number
 /// </summary>
 /// <param name="context">SSL context</param>
 /// <param name="address">IP address</param>
 /// <param name="port">Port number</param>
 public SslServer(SslContext context, IPAddress address, int port) : this(context, new IPEndPoint(address, port))
 {
 }
示例#5
0
 /// <summary>
 /// Initialize SSL client with a given server IP address and port number
 /// </summary>
 /// <param name="context">SSL context</param>
 /// <param name="address">IP address</param>
 /// <param name="port">Port number</param>
 public SslClient(SslContext context, string address, int port) : this(context, new IPEndPoint(IPAddress.Parse(address), port))
 {
     Address = address;
 }
 public SocketClient(SslContext context, string address, int port) : base(context, address, port)
 {
     ToBeSentQueue         = new Queue <DataModel>(1_000_000);
     AwaitingResponseItems = new List <DataModel>(1_000_000);
 }
示例#7
0
 public ChatClient(SslContext context, string address, int port) : base(context, address, port)
 {
 }