예제 #1
0
        public void Test()
        {
            byte[] encryptionKey = new byte[16];
            Random.NextBytes(encryptionKey);

            Console.WriteLine("Starting server");
            DoubleServerHandler serverHandler = new DoubleServerHandler();
            DoubleServer        server        = new DoubleServer(serverHandler, 1, 1, Port);

            serverHandler.Server = server;

            Console.WriteLine("Starting client");
            DoubleClientHandler clientHandler = new DoubleClientHandler();
            DoubleClient        client        = new DoubleClient(clientHandler, encryptionKey, encryptionKey, Ip, Port);

            clientHandler.Client = client;
            client.Start();

            lock (client) {
                clientHandler.MaySend = true;
                Monitor.Pulse(client);
                Console.WriteLine("Main thread waiting");
                Monitor.Wait(client);
            }

            Console.WriteLine("Closing client");
            client.Close();
            Console.WriteLine("Closing server");
            server.Close();
        }
예제 #2
0
 /// <summary>
 /// Initializes the networking and starts to connect.
 /// </summary>
 public static void Start(IPAddress ip, OnConnected onConnected)
 {
     Assert.IsNull(_client, "The NetworkClient is already initialized.");
     LocalId  = 0;
     _handler = new DoubleClientHandler(onConnected);
     byte[] encryptionKey      = new byte[16];
     byte[] authenticationData = encryptionKey;
     _client = new DoubleClient(_handler, encryptionKey, authenticationData, ip, NetworkUtils.Port);
     _client.Start();
 }
예제 #3
0
        private void OnConnectButtonClick(object sender, RoutedEventArgs e)
        {
            if (!IPAddress.TryParse(AddressInput.Text, out IPAddress ip))
            {
                StatusText.Text = "Invalid IP";
                return;
            }

            if (!Regex.IsMatch(PortInput.Text, "[0-9]+") || !int.TryParse(PortInput.Text, out int port))
            {
                StatusText.Text = "Invalid port";
                return;
            }

            ConnectButton.IsEnabled = false;
            StatusText.Text         = "Connecting...";
            byte[] encryptionKey = new byte[16];             //This is obviously not how it should be done
            _client = new DoubleClient(this, encryptionKey, encryptionKey, ip, port);
            _client.Start();
        }