diff --git a/ClientApp/ClientApp.csproj b/ClientApp/ClientApp.csproj
index 637f86c..3fdfbd2 100644
--- a/ClientApp/ClientApp.csproj
+++ b/ClientApp/ClientApp.csproj
@@ -21,13 +21,13 @@
Always
- Always
+ PreserveNewest
- Always
+ PreserveNewest
- Always
+ PreserveNewest
Always
diff --git a/ClientApp/Utils/EngineConnection.cs b/ClientApp/Utils/EngineConnection.cs
index 9f5a816..7d56a3b 100644
--- a/ClientApp/Utils/EngineConnection.cs
+++ b/ClientApp/Utils/EngineConnection.cs
@@ -75,7 +75,7 @@ namespace ClientApp.Utils
noVRResponseTimer.Elapsed += noVRResponseTimeout;
noVRResponseTimer.AutoReset = false;
noVRResponseTimer.Enabled = false;
-
+
}
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs
index 15669b6..81f245a 100644
--- a/DoctorApp/Utils/Client.cs
+++ b/DoctorApp/Utils/Client.cs
@@ -130,6 +130,8 @@ namespace DoctorApp.Utils
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
+ if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.client.Connected)
+ return;
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
@@ -192,6 +194,7 @@ namespace DoctorApp.Utils
public void Dispose()
{
Debug.WriteLine("client dispose called");
+ sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
this.stream.Dispose();
this.client.Dispose();
}
diff --git a/Server/Client.cs b/Server/Client.cs
index d7c6e6c..cbe11ce 100644
--- a/Server/Client.cs
+++ b/Server/Client.cs
@@ -34,7 +34,7 @@ namespace Server
private void OnRead(IAsyncResult ar)
{
- if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
+ if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
return;
int receivedBytes = this.stream.EndRead(ar);
@@ -65,7 +65,7 @@ namespace Server
}
}
- if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
+ if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
return;
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
@@ -125,7 +125,7 @@ namespace Server
break;
case DataParser.DISCONNECT:
- communication.Disconnect(this);
+ communication.LogOff(this);
break;
case DataParser.MESSAGE:
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
diff --git a/Server/Communication.cs b/Server/Communication.cs
index 304606d..563efc6 100644
--- a/Server/Communication.cs
+++ b/Server/Communication.cs
@@ -19,11 +19,12 @@ namespace Server
set
{
this.mDoctor = value;
- this.clients.ForEach((client) =>
- {
- this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
- client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username));
- });
+ if (this.mDoctor != null)
+ this.clients.ForEach((client) =>
+ {
+ this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
+ client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username));
+ });
}
}
public Communication(TcpListener listener)
@@ -50,12 +51,6 @@ namespace Server
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
}
- internal void Disconnect(Client client)
- {
- clients.Remove(client);
- Doctor.sendMessage(DataParser.getDisconnectJson(client.username));
- }
-
public void NewLogin(Client client)
{
this.clients.Add(client);
@@ -76,6 +71,7 @@ namespace Server
});
this.Doctor = null;
}
+ Doctor?.sendMessage(DataParser.getDisconnectJson(client.username));
this.clients.Remove(client);
}