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:
@@ -16,7 +16,7 @@ namespace ErgometerServer
|
|||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
int session;
|
public int session { get; }
|
||||||
|
|
||||||
bool running;
|
bool running;
|
||||||
bool loggedin;
|
bool loggedin;
|
||||||
@@ -36,14 +36,14 @@ namespace ErgometerServer
|
|||||||
|
|
||||||
metingen = new List<Meting>();
|
metingen = new List<Meting>();
|
||||||
chat = new List<ChatMessage>();
|
chat = new List<ChatMessage>();
|
||||||
|
session = FileHandler.GenerateSession();
|
||||||
|
Console.WriteLine("Generated new session: " + session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
session = FileHandler.GenerateSession();
|
|
||||||
Console.WriteLine("Generated new session: " + session);
|
|
||||||
NetHelper.SendNetCommand(client, new NetCommand(session));
|
NetHelper.SendNetCommand(client, new NetCommand(session));
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
@@ -72,10 +72,12 @@ namespace ErgometerServer
|
|||||||
break;
|
break;
|
||||||
case NetCommand.CommandType.DATA:
|
case NetCommand.CommandType.DATA:
|
||||||
metingen.Add(input.Meting);
|
metingen.Add(input.Meting);
|
||||||
|
server.sendToDoctor(input);
|
||||||
FileHandler.WriteMetingen(session, metingen);
|
FileHandler.WriteMetingen(session, metingen);
|
||||||
break;
|
break;
|
||||||
case NetCommand.CommandType.CHAT:
|
case NetCommand.CommandType.CHAT:
|
||||||
chat.Add(new ChatMessage(name, input.ChatMessage));
|
chat.Add(new ChatMessage(name, input.ChatMessage));
|
||||||
|
server.sendToDoctor(input);
|
||||||
Console.WriteLine(name + ": " + input.ChatMessage);
|
Console.WriteLine(name + ": " + input.ChatMessage);
|
||||||
break;
|
break;
|
||||||
case NetCommand.CommandType.LOGOUT:
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ namespace ErgometerServer
|
|||||||
{
|
{
|
||||||
class DoctorSessionThread
|
class DoctorSessionThread
|
||||||
{
|
{
|
||||||
private int session;
|
public int session { get; }
|
||||||
private TcpClient client;
|
private TcpClient client;
|
||||||
private DoctorThread doctor;
|
private DoctorThread doctor;
|
||||||
|
private Boolean running;
|
||||||
|
|
||||||
public DoctorSessionThread(int session, TcpClient client, DoctorThread doctor)
|
public DoctorSessionThread(int session, TcpClient client, DoctorThread doctor)
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,11 @@ namespace ErgometerServer
|
|||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
running = true;
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Runtime.Remoting.Lifetime;
|
using System.Runtime.Remoting.Lifetime;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -12,7 +13,6 @@ namespace ErgometerServer
|
|||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
ArrayList threads;
|
|
||||||
|
|
||||||
bool running;
|
bool running;
|
||||||
bool loggedin;
|
bool loggedin;
|
||||||
@@ -23,7 +23,6 @@ namespace ErgometerServer
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.name = "Unknown";
|
this.name = "Unknown";
|
||||||
this.threads = new ArrayList();
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.loggedin = false;
|
this.loggedin = false;
|
||||||
}
|
}
|
||||||
@@ -34,19 +33,28 @@ namespace ErgometerServer
|
|||||||
loggedin = true;
|
loggedin = true;
|
||||||
while (loggedin && running)
|
while (loggedin && running)
|
||||||
{
|
{
|
||||||
if (threads.Count < server.clients.Count)
|
NetCommand input = NetHelper.ReadNetCommand(client);
|
||||||
|
|
||||||
|
switch (input.Type)
|
||||||
{
|
{
|
||||||
DoctorSessionThread dt = new DoctorSessionThread(1, client, this);
|
case NetCommand.CommandType.LOGOUT:
|
||||||
threads.Add(dt);
|
loggedin = false;
|
||||||
Thread thread = new Thread(new ThreadStart(dt.run));
|
Console.WriteLine("Doctor logged out");
|
||||||
thread.Start();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,14 +73,27 @@ namespace ErgometerServer
|
|||||||
thread.Start();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user