From d06d621b13d897ce72b52e4d90818561ba90d6d6 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 30 Sep 2020 12:13:59 +0200 Subject: [PATCH] added necessary methods and added method sig to cw of engineconnect --- Client/EngineConnect.cs | 97 ------------------------------- RH-Engine/ServerResponseReader.cs | 2 +- 2 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 Client/EngineConnect.cs diff --git a/Client/EngineConnect.cs b/Client/EngineConnect.cs deleted file mode 100644 index 78dc20c..0000000 --- a/Client/EngineConnect.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using RH_Engine; -using System.Net.Sockets; - -namespace Client -{ - public delegate void HandleSerial(string message); - - public sealed class EngineConnect - { - private static EngineConnect instance = null; - private static readonly object padlock = new object(); - - - private static PC[] PCs = { - //new PC("DESKTOP-M2CIH87", "Fabian"), - //new PC("T470S", "Shinichi"), - //new PC("DESKTOP-DHS478C", "semme"), - new PC("HP-ZBOOK-SEM", "Sem"), - //new PC("DESKTOP-TV73FKO", "Wouter"), - new PC("DESKTOP-SINMKT1", "Ralf van Aert"), - //new PC("NA", "Bart") - }; - - private static ServerResponseReader serverResponseReader; - private static string sessionId = string.Empty; - private static string tunnelId = string.Empty; - private static string routeId = string.Empty; - private static string panelId = string.Empty; - private static string bikeId = string.Empty; - - private static Dictionary serialResponses = new Dictionary(); - - - EngineConnect() - { - - } - - public static EngineConnect INSTANCE - { - get - { - lock (padlock) - { - if (instance == null) - { - instance = new EngineConnect(); - } - }return instance; - } - } - - public static void Connect() - { - TcpClient client = new TcpClient("145.48.6.10", 6666); - - CreateConnection(client.GetStream()); - } - - /// - /// connects to the server and creates the tunnel - /// - /// the network stream to use - private static void CreateConnection(NetworkStream stream) - { - initReader(stream); - - WriteTextMessage(stream, "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}"); - - // wait until we have got a sessionId - while (sessionId == string.Empty) { } - - string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + sessionId + "\"}}"; - - WriteTextMessage(stream, tunnelCreate); - - // wait until we have a tunnel id - while (tunnelId == string.Empty) { } - Console.WriteLine("got tunnel id! sending commands..."); - sendCommands(stream, tunnelId); - } - } - - /// - /// initializes and starts the reading of the responses from the vr server - /// - /// the networkstream - private static void initReader(NetworkStream stream) - { - serverResponseReader = new ServerResponseReader(stream); - serverResponseReader.callback = HandleResponse; - serverResponseReader.StartRead(); - } -} diff --git a/RH-Engine/ServerResponseReader.cs b/RH-Engine/ServerResponseReader.cs index feeef05..17e86ba 100644 --- a/RH-Engine/ServerResponseReader.cs +++ b/RH-Engine/ServerResponseReader.cs @@ -31,7 +31,7 @@ namespace RH_Engine } else { - Console.WriteLine("Starting loop for reading"); + Console.WriteLine("[SERVERRESPONSEREADER] Starting loop for reading"); while (true) { string res = ReadPrefMessage(Stream);