コード例 #1
0
ファイル: Program.cs プロジェクト: Jenjam/TESTPROJ
        /// <summary>
        /// This method reads server's response
        /// </summary>
        /// <param name="stream"></param>
        public static void readMessage(NetworkStream stream, ClientServices servicesSrc)
        {
            Int32 bytes = 0;

            Byte[] dataLong = new Byte[4096];
            bytes = stream.Read(dataLong, 0, dataLong.Length);
            string response        = Encoding.UTF8.GetString(dataLong, 0, bytes);
            string decryptedString = Cryptography.DecryptString(response);

            Request receivedRequest = servicesSrc.FunctionCode(decryptedString);
        }
コード例 #2
0
ファイル: InterfaceGame.xaml.cs プロジェクト: Jenjam/TESTPROJ
        private async void ReadMessage()
        {
            var status = false;

            while (!status)
            {
                try
                {
                    Int32  bytes    = 0;
                    Byte[] dataLong = new Byte[4096];
                    bytes = await services.Stream.ReadAsync(dataLong, 0, dataLong.Length);

                    string  response        = Encoding.UTF8.GetString(dataLong, 0, bytes);
                    Request receivedRequest = services.FunctionCode(Cryptography.DecryptString(response));

                    if (receivedRequest.Code == "refreshAvailableDev" && receivedRequest.Type == "client")
                    {
                        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            lstDeveloperOwned.ItemsSource      = new List <Developer>();
                            services.CurrentGame.DeveloperList = JsonConvert.DeserializeObject <List <Developer> >(receivedRequest.Payload);
                            lstDeveloperOwned.ItemsSource      = services.CurrentGame.DeveloperList;
                        });
                    }

                    if (receivedRequest.Code == "launchGame" && receivedRequest.Type == "server")
                    {
                    }

                    services.Stream.Flush();
                }

                catch (Exception ex)
                {
                    status = true;
                }
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: Jenjam/TESTPROJ
        private async void ReadMessage()
        {
            var status = false;

            while (!status)
            {
                try
                {
                    Int32  bytes    = 0;
                    Byte[] dataLong = new Byte[4096];
                    bytes = await services.Stream.ReadAsync(dataLong, 0, dataLong.Length);

                    string  response        = Encoding.UTF8.GetString(dataLong, 0, bytes);
                    Request receivedRequest = services.FunctionCode(Cryptography.DecryptString(response));
                    string  log;

                    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        this.clientListBox.Items.Add("Received from server: " + Cryptography.DecryptString(response));
                    });

                    if (receivedRequest.Code == "launchGame" && receivedRequest.Type == "server")
                    {
                        log = "Launching the game...";
                        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            status = true;
                            this.Frame.Navigate(typeof(InterfaceGame), services);
                        });
                    }

                    else
                    {
                        log = Cryptography.DecryptString(response);
                        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            this.clientListBox.Items.Add(log);
                        });
                    }

                    services.Stream.Flush();
                }

                catch (Exception ex)
                {
                    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        this.clientListBox.Items.Add("CRITICAL ERROR: " + ex.Message);
                        // Re-enabling UI elements
                        txtIP.IsEnabled    = true;
                        txtPort.IsEnabled  = true;
                        txtLogin.IsEnabled = true;
                        valid.IsEnabled    = true;

                        // Hiding progressRing
                        progressRing.Visibility = Visibility.Collapsed;
                        progressRing.IsActive   = false;
                    });

                    status = true;
                }
            }
        }