From f31cdeb4679734bc92ea904614bf3ec7f2ea1fb0 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 7 Oct 2020 11:52:14 +0200 Subject: [PATCH 1/6] some writelines --- Client/Client.cs | 3 +++ RH-Engine/Program.cs | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index 1a3392a..b4e605d 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -103,14 +103,17 @@ namespace Client } break; case DataParser.START_SESSION: + Console.WriteLine("Start session identifier"); this.sessionRunning = true; sendMessage(DataParser.getStartSessionJson()); break; case DataParser.STOP_SESSION: + Console.WriteLine("Stop session identifier"); this.sessionRunning = false; sendMessage(DataParser.getStopSessionJson()); break; case DataParser.SET_RESISTANCE: + Console.WriteLine("Set resistance identifier"); if (this.handler == null) { Console.WriteLine("handler is null"); diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index 52c29a6..7bd7770 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -226,7 +226,6 @@ namespace RH_Engine -<<<<<<< HEAD //Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand)); //command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx"); @@ -245,9 +244,8 @@ namespace RH_Engine // Console.WriteLine("Color panel: " + ReadPrefMessage(stream)); // WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel)); // Console.WriteLine("Swap panel: " + ReadPrefMessage(stream)); -======= Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand)); ->>>>>>> develop + } /// From bff4718d3f9cf314964b1b169b46505e421a8112 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 7 Oct 2020 12:51:09 +0200 Subject: [PATCH 2/6] added route to client vr scene --- Client/Client.cs | 9 ++++- Client/EngineConnection.cs | 75 ++++++++++++++++++++++++++++++++------ Client/Program.cs | 2 +- Server/Client.cs | 2 + 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index 9115f01..e4d1d77 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -38,6 +38,7 @@ namespace Client { engineConnection = EngineConnection.INSTANCE; engineConnection.OnNoTunnelId = retryEngineConnection; + engineConnection.OnSuccessFullConnection = engineConnected; if (!engineConnection.Connected) engineConnection.Connect(); } @@ -53,6 +54,12 @@ namespace Client engineConnection.CreateConnection(); } + private void engineConnected() + { + engineConnection.initScene(); + if (this.sessionRunning) engineConnection.StartRouteFollow(); + } + /// /// callback method for when the TCP client is connected /// @@ -193,7 +200,6 @@ namespace Client throw new ArgumentNullException("no bytes"); } byte[] message = DataParser.GetRawDataMessage(bytes); - Console.WriteLine("got bpm message: " + message); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } @@ -212,7 +218,6 @@ namespace Client throw new ArgumentNullException("no bytes"); } byte[] message = DataParser.GetRawDataMessage(bytes); - Console.WriteLine("got bike message: " + message); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index 4905911..a0222a1 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -8,12 +8,14 @@ namespace Client { public delegate void HandleSerial(string message); public delegate void HandleNoTunnelId(); + public delegate void OnSuccessfullConnection(); public sealed class EngineConnection { private static EngineConnection instance = null; private static readonly object padlock = new object(); public HandleNoTunnelId OnNoTunnelId; + public OnSuccessfullConnection OnSuccessFullConnection; private static PC[] PCs = { @@ -29,9 +31,11 @@ namespace Client private static ServerResponseReader serverResponseReader; private static string sessionId = string.Empty; private static string tunnelId = string.Empty; + private static string cameraId = string.Empty; private static string routeId = string.Empty; private static string panelId = string.Empty; private static string bikeId = string.Empty; + private static string headId = string.Empty; private static NetworkStream stream; @@ -45,6 +49,9 @@ namespace Client } + /// + /// Singleton constructor + /// public static EngineConnection INSTANCE { get @@ -60,6 +67,11 @@ namespace Client } } + + + /// + /// connects to the vr engine and initalizes the serverResponseReader + /// public void Connect() { TcpClient client = new TcpClient("145.48.6.10", 6666); @@ -68,6 +80,19 @@ namespace Client CreateConnection(); } + /// + /// initializes and starts the reading of the responses from the vr server + /// + /// the networkstream + private void initReader() + { + serverResponseReader = new ServerResponseReader(stream); + serverResponseReader.callback = HandleResponse; + serverResponseReader.StartRead(); + Connected = true; + } + + #region VR Message traffic /// /// connects to the server and creates the tunnel /// @@ -89,20 +114,10 @@ namespace Client if (tunnelId != null) { Write("got tunnel id! " + tunnelId); + OnSuccessFullConnection?.Invoke(); } - mainCommand = new Command(tunnelId); - } - /// - /// initializes and starts the reading of the responses from the vr server - /// - /// the networkstream - private void initReader() - { - serverResponseReader = new ServerResponseReader(stream); - serverResponseReader.callback = HandleResponse; - serverResponseReader.StartRead(); - Connected = true; + } /// @@ -117,6 +132,7 @@ namespace Client if (id == "session/list") { sessionId = JSONParser.GetSessionID(message, PCs); + Write("got session id"); } else if (id == "tunnel/create") { @@ -139,6 +155,39 @@ namespace Client } } + public void initScene() + { + mainCommand = new Command(tunnelId); + + // reset the scene + WriteTextMessage(mainCommand.ResetScene()); + + //Get sceneinfo and set the id's + SendMessageAndOnResponse(mainCommand.GetSceneInfoCommand("sceneinfo"), "sceneinfo", + (message) => + { + //Console.WriteLine("\r\n\r\n\r\nscene info" + message); + cameraId = JSONParser.GetIdSceneInfoChild(message, "Camera"); + string headId = JSONParser.GetIdSceneInfoChild(message, "Head"); + string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand"); + string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand"); + + //Force(stream, mainCommand.DeleteNode(handLeftId, "deleteHandL"), "deleteHandL", (message) => Console.WriteLine("Left hand deleted")); + //Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted")); + }); + // add the route and set the route id + SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message)); + } + + internal void StartRouteFollow() + { + throw new NotImplementedException(); + } + + #endregion + + #region message send/receive + /// /// method that sends the speciefied message with the specified serial, and executes the given action upon receivind a reply from the server with this serial. /// @@ -169,6 +218,8 @@ namespace Client //Write("sent message " + message); } + + #endregion public void Write(string msg) { Console.WriteLine( "[ENGINECONNECT] " + msg); diff --git a/Client/Program.cs b/Client/Program.cs index 303b929..80b7fd8 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -11,7 +11,7 @@ namespace Client { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Console.WriteLine("// Connecting... //"); //connect fiets? Client client = new Client(); diff --git a/Server/Client.cs b/Server/Client.cs index a38f747..3fa7ba0 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -142,7 +142,9 @@ namespace Server } else if (DataParser.isRawData(message)) { + // print the raw data Console.WriteLine(BitConverter.ToString(payloadbytes)); + // TODO change, checking for length is not that safe if (payloadbytes.Length == 8) { saveData?.WriteDataRAWBike(payloadbytes); From 26a784277ac7f1867a4265cd1ba21f575bf9d613 Mon Sep 17 00:00:00 2001 From: Logophilist Date: Wed, 7 Oct 2020 12:58:50 +0200 Subject: [PATCH 3/6] Panel now shows more data --- RH-Engine/Command.cs | 45 ++++++++++++++++++++++++++++++++++++---- RH-Engine/Program.cs | 49 ++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/RH-Engine/Command.cs b/RH-Engine/Command.cs index 3875448..ba8a6c0 100644 --- a/RH-Engine/Command.cs +++ b/RH-Engine/Command.cs @@ -164,7 +164,7 @@ namespace RH_Engine return JsonConvert.SerializeObject(Payload(payload)); } - public string bikeSpeed(string uuidPanel, string serialCode, double speed) + private string showOnPanel(string uuidPanel, string serialCode, string mText, int index) { dynamic payload = new { @@ -173,9 +173,9 @@ namespace RH_Engine data = new { id = uuidPanel, - text = "Speed: " + speed.ToString(), - position = new int[] { 4, 24 }, - size = 36.0, + text = mText, + position = new int[] { 4, 24 + index * 32 }, + size = 32.0, color = new int[] { 0, 0, 0, 1 }, font = "segoeui" } @@ -184,6 +184,43 @@ namespace RH_Engine return JsonConvert.SerializeObject(Payload(payload)); } + + public string showBikespeed(string uuidPanel, string serialCode, double speed) + { + //dynamic payload = new + //{ + // id = "scene/panel/drawtext", + // serial = serialCode, + // data = new + // { + // id = uuidPanel, + // text = "Speed: " + speed + " m/s", + // position = new int[] { 4, 24 }, + // size = 36.0, + // color = new int[] { 0, 0, 0, 1 }, + // font = "segoeui" + // } + //}; + + //return JsonConvert.SerializeObject(Payload(payload)); + return showOnPanel(uuidPanel, serialCode, "Speed: " + speed + " m/s", 0); + } + + public string showHeartrate(string uuidPanel, string serialCode, int bpm) + { + return showOnPanel(uuidPanel, serialCode, "Heartrate: " + bpm + " bpm", 1); + } + + public string showPower(string uuidPanel, string serialCode, double power) + { + return showOnPanel(uuidPanel, serialCode, "Inst. Power: " + power + " W", 2); + } + + public string showResistance(string uuidPanel, string serialCode, double resistance) + { + return showOnPanel(uuidPanel, serialCode, "Resistance: " + resistance + " %", 3); + } + public string SwapPanelCommand(string uuid) { dynamic payload = new diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index ae25339..4d11703 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -81,7 +81,11 @@ namespace RH_Engine //Console.WriteLine("GOT MESSAGE WITH SERIAL: " + message + "\n\n\n"); string serial = JSONParser.GetSerial(message); //Console.WriteLine("Got serial " + serial); - if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message); + if (serialResponses.ContainsKey(serial)) + { + serialResponses[serial].Invoke(message); + serialResponses.Remove(serial); + } } } @@ -181,19 +185,9 @@ namespace RH_Engine panelId = JSONParser.getPanelID(message); WriteTextMessage(stream, mainCommand.ColorPanel(panelId)); WriteTextMessage(stream, mainCommand.ClearPanel(panelId)); - - SendMessageAndOnResponse(stream, mainCommand.MoveTo(panelId, "panelMove", new float[] { 0f, 0f, 0f }, "Z", 1, 5), "panelMove", - (message) => - { - Console.WriteLine(message); - - SendMessageAndOnResponse(stream, mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed", - (message) => - { - WriteTextMessage(stream, mainCommand.SwapPanel(panelId)); - }); - }); + + showPanel(stream, mainCommand, 5.3, 83, 52, 53); //while (!(speedReplied && moveReplied)) { } @@ -325,6 +319,35 @@ namespace RH_Engine return res; } + + private static void showPanel(NetworkStream stream, Command mainCommand, double bikeSpeed, int bpm, int power, int resistance) + { + SendMessageAndOnResponse(stream, mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(stream, mainCommand.showHeartrate(panelId, "bpm", bpm), "bpm", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(stream, mainCommand.showPower(panelId, "power", power), "power", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(stream, mainCommand.showResistance(panelId, "resistance", resistance), "resistance", + (message) => + { + // TODO check if is drawn + }); + + // Check if every text is drawn! + + WriteTextMessage(stream, mainCommand.SwapPanel(panelId)); + } + private static void SetFollowSpeed(float speed, NetworkStream stream, Command mainCommand) { WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); From 57aa9b6deb89e98c4947ab1cf74da26d2d3b8ff3 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 7 Oct 2020 15:08:45 +0200 Subject: [PATCH 4/6] finished reconnecting on sim not started and then sending the commands --- Client/Client.cs | 4 ++- Client/EngineConnection.cs | 68 +++++++++++++++++++++++++++++++++----- RH-Engine/Program.cs | 1 - 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index e4d1d77..dc6fa20 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -56,8 +56,9 @@ namespace Client private void engineConnected() { + Console.WriteLine("successfully connected to VR engine"); engineConnection.initScene(); - if (this.sessionRunning) engineConnection.StartRouteFollow(); + if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow(); } /// @@ -127,6 +128,7 @@ namespace Client case DataParser.START_SESSION: Console.WriteLine("Session started!"); this.sessionRunning = true; + if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow(); sendMessage(DataParser.getStartSessionJson()); break; case DataParser.STOP_SESSION: diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index a0222a1..84aaddb 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -37,6 +37,8 @@ namespace Client private static string bikeId = string.Empty; private static string headId = string.Empty; + public bool FollowingRoute = false; + private static NetworkStream stream; private static Dictionary serialResponses = new Dictionary(); @@ -89,7 +91,6 @@ namespace Client serverResponseReader = new ServerResponseReader(stream); serverResponseReader.callback = HandleResponse; serverResponseReader.StartRead(); - Connected = true; } #region VR Message traffic @@ -110,12 +111,14 @@ namespace Client WriteTextMessage(tunnelCreate); // wait until we have a tunnel id - while (tunnelId == string.Empty) { } - if (tunnelId != null) - { - Write("got tunnel id! " + tunnelId); - OnSuccessFullConnection?.Invoke(); - } + //while (tunnelId == string.Empty) { } + //if (tunnelId != null) + //{ + // Write("got tunnel id! " + tunnelId); + // Connected = true; + // OnSuccessFullConnection?.Invoke(); + + //} } @@ -132,17 +135,23 @@ namespace Client if (id == "session/list") { sessionId = JSONParser.GetSessionID(message, PCs); - Write("got session id"); } else if (id == "tunnel/create") { tunnelId = JSONParser.GetTunnelID(message); + Console.WriteLine("set tunnel id to " + tunnelId); if (tunnelId == null) { Write("could not find a valid tunnel id!"); OnNoTunnelId?.Invoke(); Connected = false; + FollowingRoute = false; return; + } else + { + Write("got tunnel id! " + tunnelId); + Connected = true; + OnSuccessFullConnection?.Invoke(); } } @@ -157,6 +166,7 @@ namespace Client public void initScene() { + Write("initializing scene..."); mainCommand = new Command(tunnelId); // reset the scene @@ -181,7 +191,47 @@ namespace Client internal void StartRouteFollow() { - throw new NotImplementedException(); + Write("Starting route follow..."); + FollowingRoute = true; + + SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID", + (message) => + { + bikeId = JSONParser.GetResponseUuid(message); + SendMessageAndOnResponse(mainCommand.addPanel("panelAdd", bikeId), "panelAdd", + (message) => + { + + panelId = JSONParser.getPanelID(message); + WriteTextMessage(mainCommand.ColorPanel(panelId)); + WriteTextMessage(mainCommand.ClearPanel(panelId)); + + + SendMessageAndOnResponse(mainCommand.MoveTo(panelId, "panelMove", new float[] { 0f, 0f, 0f }, "Z", 1, 5), "panelMove", + (message) => + { + Console.WriteLine(message); + + SendMessageAndOnResponse(mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed", + (message) => + { + WriteTextMessage(mainCommand.SwapPanel(panelId)); + }); + }); + + + //while (!(speedReplied && moveReplied)) { } + + while (cameraId == string.Empty) { } + SetFollowSpeed(5.0f); + }); + }); + } + + private void SetFollowSpeed(float speed) + { + WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); + WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed)); } #endregion diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index ae25339..0bec77e 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -329,7 +329,6 @@ namespace RH_Engine { WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed)); - //WriteTextMessage(stream, mainCommand.RouteFollow(routeId, panelId, speed, 1f, "XYZ", 1, false, new float[] { 0, 0, 0 }, new float[] { 0f, 5f, 5f })); } //string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector) private static void Force(NetworkStream stream, string message, string serial, HandleSerial action) From 651a44762b15979c101b7b3bc4b9d2bed16cc2a1 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 7 Oct 2020 15:15:42 +0200 Subject: [PATCH 5/6] input test --- Client/Client.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index dc6fa20..e6a62b4 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -48,8 +48,9 @@ namespace Client private void retryEngineConnection() { Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!"); - Console.WriteLine("-- Press any key to retry connecting to the VR engine."); - Console.ReadKey(); + Console.WriteLine("-- Press ENTER to retry connecting to the VR engine."); + Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine"); + Console.WriteLine(Console.Read()); engineConnection.CreateConnection(); } From 847fa68acb458bcd4e79308b2f0f55008e10eb23 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 7 Oct 2020 16:06:16 +0200 Subject: [PATCH 6/6] fix for displaying things on vr scene --- Client/Client.cs | 11 ++++-- Client/EngineConnection.cs | 61 ++++++++++++++++++------------- RH-Engine/ServerResponseReader.cs | 14 ++++++- 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index e6a62b4..008c09d 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -50,9 +50,14 @@ namespace Client Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!"); Console.WriteLine("-- Press ENTER to retry connecting to the VR engine."); Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine"); - Console.WriteLine(Console.Read()); - - engineConnection.CreateConnection(); + string input = Console.ReadLine(); + if (input == string.Empty) engineConnection.CreateConnection(); + else + { + Console.WriteLine("Skipping connecting to VR engine..."); + engineConnection.Stop(); + } + } private void engineConnected() diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index 84aaddb..5a89713 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -110,16 +110,6 @@ namespace Client WriteTextMessage(tunnelCreate); - // wait until we have a tunnel id - //while (tunnelId == string.Empty) { } - //if (tunnelId != null) - //{ - // Write("got tunnel id! " + tunnelId); - // Connected = true; - // OnSuccessFullConnection?.Invoke(); - - //} - } @@ -201,26 +191,13 @@ namespace Client SendMessageAndOnResponse(mainCommand.addPanel("panelAdd", bikeId), "panelAdd", (message) => { - + panelId = JSONParser.getPanelID(message); WriteTextMessage(mainCommand.ColorPanel(panelId)); WriteTextMessage(mainCommand.ClearPanel(panelId)); - SendMessageAndOnResponse(mainCommand.MoveTo(panelId, "panelMove", new float[] { 0f, 0f, 0f }, "Z", 1, 5), "panelMove", - (message) => - { - Console.WriteLine(message); - - SendMessageAndOnResponse(mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed", - (message) => - { - WriteTextMessage(mainCommand.SwapPanel(panelId)); - }); - }); - - - //while (!(speedReplied && moveReplied)) { } + showPanel(mainCommand, 5.3, 83, 52, 53); while (cameraId == string.Empty) { } SetFollowSpeed(5.0f); @@ -228,6 +205,34 @@ namespace Client }); } + private void showPanel(Command mainCommand, double bikeSpeed, int bpm, int power, int resistance) + { + SendMessageAndOnResponse(mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(mainCommand.showHeartrate(panelId, "bpm", bpm), "bpm", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(mainCommand.showPower(panelId, "power", power), "power", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(mainCommand.showResistance(panelId, "resistance", resistance), "resistance", + (message) => + { + // TODO check if is drawn + }); + + // Check if every text is drawn! + + WriteTextMessage(mainCommand.SwapPanel(panelId)); + } + private void SetFollowSpeed(float speed) { WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); @@ -270,6 +275,12 @@ namespace Client } #endregion + + public void Stop() + { + serverResponseReader.Stop(); + + } public void Write(string msg) { Console.WriteLine( "[ENGINECONNECT] " + msg); diff --git a/RH-Engine/ServerResponseReader.cs b/RH-Engine/ServerResponseReader.cs index 17e86ba..bafa442 100644 --- a/RH-Engine/ServerResponseReader.cs +++ b/RH-Engine/ServerResponseReader.cs @@ -9,6 +9,8 @@ namespace RH_Engine public class ServerResponseReader { + private bool running; + private Thread t; public OnResponse callback { get; set; @@ -23,7 +25,7 @@ namespace RH_Engine public void StartRead() { - Thread t = new Thread(() => + t = new Thread(() => { if (this.callback == null) { @@ -31,8 +33,9 @@ namespace RH_Engine } else { + running = true; Console.WriteLine("[SERVERRESPONSEREADER] Starting loop for reading"); - while (true) + while (running) { string res = ReadPrefMessage(Stream); //Console.WriteLine("[SERVERRESPONSEREADER] got message from server: " + res); @@ -44,6 +47,13 @@ namespace RH_Engine t.Start(); } + public void Stop() + { + running = false; + t.Join(); + Stream.Close(); + } + /// /// reads a response from the server ///