From 5f2e325cb132887b43d567e9552bd3c330549947 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 27 Oct 2020 21:35:07 +0100 Subject: [PATCH] [ADD] added chat to all method from docter, it works but there is sometimes an error in the doctor client app that the buffer in OnRead is full, so will try to fix that tomorrow --- ClientApp/Utils/Client.cs | 3 +++ DoctorApp/Utils/Client.cs | 1 + DoctorApp/ViewModels/ClientInfoViewModel.cs | 1 + DoctorApp/Views/ClientInfoView.xaml | 1 + 4 files changed, 6 insertions(+) diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index a96a2ab..4b347d5 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -190,6 +190,9 @@ namespace ClientApp.Utils expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0); } + if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.client.Connected) + return; + ar.AsyncWaitHandle.WaitOne(); this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null); } diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs index 1087346..20b3137 100644 --- a/DoctorApp/Utils/Client.cs +++ b/DoctorApp/Utils/Client.cs @@ -136,6 +136,7 @@ namespace DoctorApp.Utils if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.client.Connected) return; + ar.AsyncWaitHandle.WaitOne(); this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null); } diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs index 4b652a5..75de46a 100644 --- a/DoctorApp/ViewModels/ClientInfoViewModel.cs +++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs @@ -77,6 +77,7 @@ namespace DoctorApp.ViewModels ChatToAll = new RelayCommand((parameter) => { + Debug.WriteLine("[CLIENTINFOVIEWMODEL] sending message to all clients"); this.parent?.SendToAllClients(((TextBox)parameter).Text); }); diff --git a/DoctorApp/Views/ClientInfoView.xaml b/DoctorApp/Views/ClientInfoView.xaml index 5057f24..c3e6bca 100644 --- a/DoctorApp/Views/ClientInfoView.xaml +++ b/DoctorApp/Views/ClientInfoView.xaml @@ -57,6 +57,7 @@