diff --git a/Client/Client.cs b/Client/Client.cs
index e9715b9..7e36c2f 100644
--- a/Client/Client.cs
+++ b/Client/Client.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Linq;
using System.Net.Sockets;
using System.Text;
@@ -55,7 +55,7 @@ namespace Client
this.stream = this.client.GetStream();
- tryLoginDoctor("hi","hi");
+ tryLogin();
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
@@ -94,7 +94,7 @@ namespace Client
if (responseStatus == "OK")
{
this.connected = true;
- initEngine();
+ //initEngine();
}
else
{
diff --git a/Client/Program.cs b/Client/Program.cs
index 89ed605..aa63eab 100644
--- a/Client/Program.cs
+++ b/Client/Program.cs
@@ -4,6 +4,7 @@ using Hardware.Simulators;
using RH_Engine;
using System.Security.Cryptography;
using System.Text;
+using System.Threading;
namespace Client
{
@@ -14,6 +15,7 @@ namespace Client
Console.WriteLine("Hello World!");
//connect fiets?
+ Thread.Sleep(20000);
Client client = new Client();
diff --git a/DokterApp/Client.cs b/DokterApp/Client.cs
index 98f6224..c9f0f73 100644
--- a/DokterApp/Client.cs
+++ b/DokterApp/Client.cs
@@ -18,10 +18,12 @@ namespace DokterApp
private IHandler handler = null;
private string username;
private string password;
+ private Del callback;
- public Client(string adress, int port, string username, string password)
+ public Client(string adress, int port, string username, string password, Del callback)
{
+ this.callback = callback;
this.username = username;
this.password = password;
this.client = new TcpClient();
@@ -82,8 +84,9 @@ namespace DokterApp
}
else
{
+ callback("yeet");
Console.WriteLine($"login failed \"{responseStatus}\"");
- tryLogin();
+ //tryLogin();
}
break;
case DataParser.START_SESSION:
@@ -173,14 +176,6 @@ namespace DokterApp
private void tryLogin()
{
//TODO File in lezen
- /*Console.WriteLine("enter username");
- string username = Console.ReadLine();
- Console.WriteLine("enter password");
- string password = Console.ReadLine();*/
-
-
-
-
string hashUser = Hashing.Hasher.HashString(username);
string hashPassword = Hashing.Hasher.HashString(password);
diff --git a/DokterApp/MainWindow.xaml b/DokterApp/MainWindow.xaml
index 092c8e5..59aedc4 100644
--- a/DokterApp/MainWindow.xaml
+++ b/DokterApp/MainWindow.xaml
@@ -17,7 +17,7 @@
-
+
diff --git a/DokterApp/MainWindow.xaml.cs b/DokterApp/MainWindow.xaml.cs
index 9d8c852..a0443bf 100644
--- a/DokterApp/MainWindow.xaml.cs
+++ b/DokterApp/MainWindow.xaml.cs
@@ -20,6 +20,7 @@ namespace DokterApp
///
public partial class MainWindow : Window
{
+ Del handler;
Client client;
public MainWindow()
{
@@ -27,18 +28,27 @@ namespace DokterApp
}
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
-
- }
+
private void Login_Click_1(object sender, RoutedEventArgs e)
{
WindowTabs windowTabs = new WindowTabs();
+ handler = windowTabs.NewTab;
+
+ this.Label.Content = "Waiting";
+ this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Text, handler);
+ while (!client.IsConnected())
+ {
+ }
+
+
windowTabs.Show();
- this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Text);
+
this.Close();
+
}
}
+
+ public delegate void Del(string message);
}
diff --git a/DokterApp/WindowTabs.xaml.cs b/DokterApp/WindowTabs.xaml.cs
index 7317aa9..ee1f4f0 100644
--- a/DokterApp/WindowTabs.xaml.cs
+++ b/DokterApp/WindowTabs.xaml.cs
@@ -31,14 +31,23 @@ namespace DokterApp
private void Button_Click(object sender, RoutedEventArgs e)
{
- TabItem newTabItem = new TabItem
- {
- Header = "Test",
- Width = 110,
- Height = 40
- };
- newTabItem.Content = new UserControlForTab();
- this.tbControl.Items.Add(newTabItem);
+ NewTab("Test");
+ }
+
+ public void NewTab(string username)
+ {
+ Application.Current.Dispatcher.Invoke((Action)delegate {
+ // your code
+ TabItem newTabItem = new TabItem
+ {
+ Header = username,
+ Width = 110,
+ Height = 40
+ };
+ newTabItem.Content = new UserControlForTab();
+ this.tbControl.Items.Add(newTabItem);
+ });
+
}
}
}
diff --git a/Server/Client.cs b/Server/Client.cs
index 0151e87..da264b6 100644
--- a/Server/Client.cs
+++ b/Server/Client.cs
@@ -38,6 +38,7 @@ namespace Server
private void OnRead(IAsyncResult ar)
{
+
int receivedBytes = this.stream.EndRead(ar);
if (totalBufferReceived + receivedBytes > 1024)
@@ -160,7 +161,7 @@ namespace Server
}
- private void sendMessage(byte[] message)
+ public void sendMessage(byte[] message)
{
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
diff --git a/Server/Communication.cs b/Server/Communication.cs
index 0d354c4..f3432c8 100644
--- a/Server/Communication.cs
+++ b/Server/Communication.cs
@@ -1,6 +1,8 @@
-using System;
+using Client;
+using System;
using System.Collections.Generic;
using System.IO.Pipes;
+using System.Linq;
using System.Net.Sockets;
using System.Text;
@@ -10,6 +12,7 @@ namespace Server
{
private TcpListener listener;
private List clients;
+ private Client doctor;
public Communication(TcpListener listener)
{
@@ -28,9 +31,19 @@ namespace Server
private void OnConnect(IAsyncResult ar)
{
+
var tcpClient = listener.EndAcceptTcpClient(ar);
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
clients.Add(new Client(this, tcpClient));
+ if (doctor == null)
+ {
+ doctor = clients.ElementAt(0);
+ }
+ else
+ {
+
+ doctor.sendMessage(DataParser.getLoginResponse("new client"));
+ }
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
}