totally changed communication between client and doctor. Needs to be tested. Also protocol needs to be changed to fix missing features.

This commit is contained in:
Aareschluchtje
2015-10-05 16:37:30 +02:00
parent c8f32ced43
commit 33697cfc3e
4 changed files with 55 additions and 19 deletions
+13 -3
View File
@@ -16,7 +16,7 @@ namespace ErgometerServer
Server server;
string name;
int session;
public int session { get; }
bool running;
bool loggedin;
@@ -36,14 +36,14 @@ namespace ErgometerServer
metingen = new List<Meting>();
chat = new List<ChatMessage>();
session = FileHandler.GenerateSession();
Console.WriteLine("Generated new session: " + session);
}
public void run()
{
running = true;
session = FileHandler.GenerateSession();
Console.WriteLine("Generated new session: " + session);
NetHelper.SendNetCommand(client, new NetCommand(session));
while (running)
@@ -72,10 +72,12 @@ namespace ErgometerServer
break;
case NetCommand.CommandType.DATA:
metingen.Add(input.Meting);
server.sendToDoctor(input);
FileHandler.WriteMetingen(session, metingen);
break;
case NetCommand.CommandType.CHAT:
chat.Add(new ChatMessage(name, input.ChatMessage));
server.sendToDoctor(input);
Console.WriteLine(name + ": " + input.ChatMessage);
break;
case NetCommand.CommandType.LOGOUT:
@@ -92,5 +94,13 @@ namespace ErgometerServer
}
}
public void writeToClient(NetCommand command)
{
NetHelper.SendNetCommand(client, command);
if (command.Type == NetCommand.CommandType.CHAT)
{
chat.Add(new ChatMessage("Doctor", command.ChatMessage));
}
}
}
}
+7 -2
View File
@@ -9,9 +9,10 @@ namespace ErgometerServer
{
class DoctorSessionThread
{
private int session;
public int session { get; }
private TcpClient client;
private DoctorThread doctor;
private Boolean running;
public DoctorSessionThread(int session, TcpClient client, DoctorThread doctor)
{
@@ -22,7 +23,11 @@ namespace ErgometerServer
public void run()
{
running = true;
while (running)
{
}
}
}
}
+18 -10
View File
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using System.Net.Sockets;
using System.Runtime.Remoting.Lifetime;
using System.Threading;
@@ -12,7 +13,6 @@ namespace ErgometerServer
Server server;
string name;
ArrayList threads;
bool running;
bool loggedin;
@@ -23,7 +23,6 @@ namespace ErgometerServer
this.client = client;
this.server = server;
this.name = "Unknown";
this.threads = new ArrayList();
this.running = false;
this.loggedin = false;
}
@@ -34,19 +33,28 @@ namespace ErgometerServer
loggedin = true;
while (loggedin && running)
{
if (threads.Count < server.clients.Count)
NetCommand input = NetHelper.ReadNetCommand(client);
switch (input.Type)
{
DoctorSessionThread dt = new DoctorSessionThread(1, client, this);
threads.Add(dt);
Thread thread = new Thread(new ThreadStart(dt.run));
thread.Start();
case NetCommand.CommandType.LOGOUT:
loggedin = false;
Console.WriteLine("Doctor logged out");
break;
case NetCommand.CommandType.CHAT:
server.sendToClient(input);
Console.WriteLine(input);
break;
default:
throw new FormatException("Unknown Command");
}
}
client.Close();
}
public void logout()
public void sendToDoctor(NetCommand command)
{
loggedin = false;
NetHelper.SendNetCommand(client, command);
}
}
}
+17 -4
View File
@@ -73,14 +73,27 @@ namespace ErgometerServer
thread.Start();
}
public void sendToDoctor()
public void sendToDoctor(NetCommand command)
{
if (doctor != null)
{
doctor.sendToDoctor(command);
}
else
{
Console.WriteLine("No doctor connected to the server yet");
}
}
public void sendToClient(int session)
public void sendToClient(NetCommand command)
{
foreach (ClientThread clientThread in clients)
{
if (clientThread.session == command.Session)
{
clientThread.writeToClient(command);
}
}
}
}
}