doctor can now disconnect

This commit is contained in:
shinichi
2020-10-19 12:52:35 +02:00
parent d98c32a508
commit 2ecc90ff2c
4 changed files with 14 additions and 15 deletions

View File

@@ -44,7 +44,7 @@ namespace ClientApp.Utils
private static string groundPlaneId = string.Empty; private static string groundPlaneId = string.Empty;
private static string terrainId = string.Empty; private static string terrainId = string.Empty;
public string DoctorMessage { get; set; }; public string DoctorMessage { get; set; }
public float BikeSpeed { get; set; } public float BikeSpeed { get; set; }
public float BikePower { get; set; } public float BikePower { get; set; }
public float BikeBPM { get; set; } public float BikeBPM { get; set; }
@@ -75,7 +75,7 @@ namespace ClientApp.Utils
noVRResponseTimer.Elapsed += noVRResponseTimeout; noVRResponseTimer.Elapsed += noVRResponseTimeout;
noVRResponseTimer.AutoReset = false; noVRResponseTimer.AutoReset = false;
noVRResponseTimer.Enabled = false; noVRResponseTimer.Enabled = false;
} }
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

View File

@@ -130,6 +130,8 @@ namespace DoctorApp.Utils
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0); 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); this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
} }
@@ -192,6 +194,7 @@ namespace DoctorApp.Utils
public void Dispose() public void Dispose()
{ {
Debug.WriteLine("client dispose called"); Debug.WriteLine("client dispose called");
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
this.stream.Dispose(); this.stream.Dispose();
this.client.Dispose(); this.client.Dispose();
} }

View File

@@ -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; return;
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null); this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
@@ -123,7 +123,7 @@ namespace Server
//set resistance on doctor GUI //set resistance on doctor GUI
break; break;
case DataParser.DISCONNECT: case DataParser.DISCONNECT:
communication.Disconnect(this); communication.LogOff(this);
break; break;
default: default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}"); Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");

View File

@@ -19,11 +19,12 @@ namespace Server
set set
{ {
this.mDoctor = value; this.mDoctor = value;
this.clients.ForEach((client) => if (this.mDoctor != null)
{ this.clients.ForEach((client) =>
this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username)); {
client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username)); this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
}); client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username));
});
} }
} }
public Communication(TcpListener listener) public Communication(TcpListener listener)
@@ -50,12 +51,6 @@ namespace Server
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null); 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) public void NewLogin(Client client)
{ {
this.clients.Add(client); this.clients.Add(client);
@@ -76,6 +71,7 @@ namespace Server
}); });
this.Doctor = null; this.Doctor = null;
} }
Doctor?.sendMessage(DataParser.getDisconnectJson(client.username));
this.clients.Remove(client); this.clients.Remove(client);
} }