|
@@ -13,23 +13,22 @@ namespace FietsClient
|
|
|
public class TcpConnection
|
|
public class TcpConnection
|
|
|
{
|
|
{
|
|
|
public TcpClient client;
|
|
public TcpClient client;
|
|
|
|
|
+ public bool isConnectedFlag { private set; get; }
|
|
|
private NetworkStream serverStream;
|
|
private NetworkStream serverStream;
|
|
|
- private CurrentData currentData;
|
|
|
|
|
|
|
+ public CurrentData currentData { private set; get; }
|
|
|
private string userID;
|
|
private string userID;
|
|
|
- private bool isConnectedFlag;
|
|
|
|
|
|
|
+ private Thread receiveThread;
|
|
|
|
|
|
|
|
public delegate void ChatmassegeDelegate(string[] data);
|
|
public delegate void ChatmassegeDelegate(string[] data);
|
|
|
public event ChatmassegeDelegate IncomingChatmessageEvent;
|
|
public event ChatmassegeDelegate IncomingChatmessageEvent;
|
|
|
|
|
|
|
|
public TcpConnection()
|
|
public TcpConnection()
|
|
|
{
|
|
{
|
|
|
- // create a connection
|
|
|
|
|
client = new TcpClient();
|
|
client = new TcpClient();
|
|
|
-
|
|
|
|
|
connect();
|
|
connect();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void onIncomingChatMessage(string[] data)
|
|
|
|
|
|
|
+ private void onIncomingChatMessage(string[] data)
|
|
|
{
|
|
{
|
|
|
ChatmassegeDelegate cMD = IncomingChatmessageEvent;
|
|
ChatmassegeDelegate cMD = IncomingChatmessageEvent;
|
|
|
if (cMD != null)
|
|
if (cMD != null)
|
|
@@ -51,8 +50,8 @@ namespace FietsClient
|
|
|
|
|
|
|
|
// create streams
|
|
// create streams
|
|
|
serverStream = client.GetStream();
|
|
serverStream = client.GetStream();
|
|
|
- Thread t = new Thread(recieve);
|
|
|
|
|
- t.Start();
|
|
|
|
|
|
|
+ receiveThread = new Thread(receive);
|
|
|
|
|
+ receiveThread.Start();
|
|
|
isConnectedFlag = true;
|
|
isConnectedFlag = true;
|
|
|
}
|
|
}
|
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -63,46 +62,48 @@ namespace FietsClient
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- public void recieve ()
|
|
|
|
|
|
|
+ public void receive()
|
|
|
{
|
|
{
|
|
|
while (true)
|
|
while (true)
|
|
|
{
|
|
{
|
|
|
byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
|
|
byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
|
|
|
serverStream.Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
|
|
serverStream.Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
|
|
|
- String response = Encoding.ASCII.GetString(bytesFrom);
|
|
|
|
|
- String[] response_parts = response.Split('|');
|
|
|
|
|
|
|
+ string response = Encoding.ASCII.GetString(bytesFrom);
|
|
|
|
|
+ string[] response_parts = response.Split('|');
|
|
|
|
|
|
|
|
if (response_parts.Length > 0)
|
|
if (response_parts.Length > 0)
|
|
|
{
|
|
{
|
|
|
switch (response_parts[0])
|
|
switch (response_parts[0])
|
|
|
{
|
|
{
|
|
|
- case "0": //login
|
|
|
|
|
|
|
+ case "0": //login and display correct window after login
|
|
|
if (response_parts.Length == 4)
|
|
if (response_parts.Length == 4)
|
|
|
{
|
|
{
|
|
|
if (response_parts[1] == "1" && response_parts[2] == "1")
|
|
if (response_parts[1] == "1" && response_parts[2] == "1")
|
|
|
{
|
|
{
|
|
|
- new DoctorForm().Show();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Form activeForm = Form.ActiveForm;
|
|
|
|
|
+ activeForm.Invoke((MethodInvoker)delegate ()
|
|
|
|
|
+ {
|
|
|
|
|
+ DoctorForm doctorForm = new DoctorForm(this);
|
|
|
|
|
+ activeForm.Hide();
|
|
|
|
|
+ doctorForm.Show();
|
|
|
|
|
+ });
|
|
|
currentData = new CurrentData(userID);
|
|
currentData = new CurrentData(userID);
|
|
|
}
|
|
}
|
|
|
- else if(response_parts[2] == "0" && response_parts[1] == "1")
|
|
|
|
|
|
|
+ else if (response_parts[2] == "0" && response_parts[1] == "1")
|
|
|
{
|
|
{
|
|
|
- PatientForm form = new PatientForm(this);
|
|
|
|
|
|
|
+
|
|
|
Form activeForm = Form.ActiveForm;
|
|
Form activeForm = Form.ActiveForm;
|
|
|
-
|
|
|
|
|
- activeForm.Invoke((MethodInvoker)delegate () {
|
|
|
|
|
|
|
+ activeForm.Invoke((MethodInvoker)delegate ()
|
|
|
|
|
+ {
|
|
|
|
|
+ PatientForm patientForm = new PatientForm(this);
|
|
|
activeForm.Hide();
|
|
activeForm.Hide();
|
|
|
- form.Show();
|
|
|
|
|
|
|
+ patientForm.Show();
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
currentData = new CurrentData(userID);
|
|
currentData = new CurrentData(userID);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
- {
|
|
|
|
|
new Login("Geen gebruiker gevonden");
|
|
new Login("Geen gebruiker gevonden");
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case "1":
|
|
case "1":
|
|
@@ -124,14 +125,12 @@ namespace FietsClient
|
|
|
// send command ( cmdID | username | password )
|
|
// send command ( cmdID | username | password )
|
|
|
this.userID = username;
|
|
this.userID = username;
|
|
|
SendString("0|" + username + "|" + password + "|");
|
|
SendString("0|" + username + "|" + password + "|");
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void SendGet(int GetWhat)
|
|
public void SendGet(int GetWhat)
|
|
|
{
|
|
{
|
|
|
// send command ( cmdID | username )
|
|
// send command ( cmdID | username )
|
|
|
- SendString( GetWhat + "|" + userID );
|
|
|
|
|
-
|
|
|
|
|
|
|
+ SendString(GetWhat + "|" + userID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void SendNewSession()
|
|
public void SendNewSession()
|
|
@@ -145,19 +144,35 @@ namespace FietsClient
|
|
|
// send command ( cmdID | username )
|
|
// send command ( cmdID | username )
|
|
|
SendString("5|" + userID + lib.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()));
|
|
SendString("5|" + userID + lib.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void SendChatMessage(string message)
|
|
|
|
|
+ {
|
|
|
|
|
+ // send command ( cmdID | username sender | username patient | message )
|
|
|
|
|
+ string protocol = "6 | " + this.userID +" | "/* + idPatient */ + " | " + message;
|
|
|
|
|
+ SendString(protocol);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void SendDistance(int distance)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendString("10|" + userID + "|" + distance);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void SendTime(int Minutes, int seconds)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendString("11|" + userID + "|" + Minutes + ":" + seconds);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- public void SendString(string s)
|
|
|
|
|
|
|
+ public void SendPower(int power)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendString("12|" + userID + "|" + power);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void SendString(string s)
|
|
|
{
|
|
{
|
|
|
byte[] b = Encoding.ASCII.GetBytes(s);
|
|
byte[] b = Encoding.ASCII.GetBytes(s);
|
|
|
serverStream.Write(b, 0, b.Length);
|
|
serverStream.Write(b, 0, b.Length);
|
|
|
serverStream.Flush();
|
|
serverStream.Flush();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void SendChatMessage(string message)
|
|
|
|
|
- {
|
|
|
|
|
- // send command ( cmdID | username sender | username patient | message )
|
|
|
|
|
- string protocol = "6 | " + this.userID +" | "/* + idPatient */ + " | " + message;
|
|
|
|
|
- SendString(protocol);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|