Server is now able to read data and confirm data it received.

This commit is contained in:
Aareschluchtje
2015-09-23 20:43:26 +02:00
parent b90dd0bfe1
commit b2de4aff69
+47 -4
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -46,10 +47,52 @@ namespace ErgometerServer
TcpClient client = obj as TcpClient;
StreamReader reader = new StreamReader(client.GetStream(), Encoding.ASCII);
StreamWriter stream = new StreamWriter(client.GetStream(), Encoding.ASCII);
string q = reader.ReadLine();
if(q == "1«")
Console.WriteLine(q);
string name = null;
int session = 0;
bool doctor;
string a = reader.ReadLine();
Console.WriteLine(a);
if (a.StartsWith("1»") && a.EndsWith("connect"))
{
Console.WriteLine("Connection established");
stream.WriteLine(a.Substring(0, a.Length - 7) + "cs");
}
string b = reader.ReadLine();
if (b.StartsWith("2»"))
{
Console.WriteLine(b);
string[] package = b.Split('»');
name = package[2];
session = int.Parse(package[1]);
doctor = package[3].Equals("doctor");
if (doctor)
{
//check password
}
else
{
Console.WriteLine("login of " + name + " succesful");
stream.WriteLine("2»" + package[1] + "»client»ls");
}
}
string c = reader.ReadLine();
ArrayList data = new ArrayList();
while (c.StartsWith("3»"))
{
Console.WriteLine(c);
data.Add(c);
stream.WriteLine("3»" + session + "»succes");
c = reader.ReadLine();
}
string d = reader.ReadLine();
ArrayList oldData = new ArrayList();
while (c.StartsWith("4»"))
{
Console.WriteLine(d);
oldData.Add(d);
stream.WriteLine("4»" + session + "»succes");
d = reader.ReadLine();
}
stream.Flush();
stream.Close();
reader.Close();