diff --git a/Client/Client.cs b/Client/Client.cs index e65204f..5b4c873 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -27,16 +27,24 @@ namespace Client this.client = new TcpClient(); this.connected = false; client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null); - - initEngine(); } private void initEngine() { engineConnection = EngineConnection.INSTANCE; + engineConnection.OnNoTunnelId = retryEngineConnection; if (!engineConnection.Connected) engineConnection.Connect(); } + 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 connection"); + Console.ReadKey(); + + engineConnection.CreateConnection(); + } + private void OnConnect(IAsyncResult ar) { this.client.EndConnect(ar); diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index 965673b..8b62c10 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -7,20 +7,22 @@ using System.Net.Sockets; namespace Client { public delegate void HandleSerial(string message); + public delegate void HandleNoTunnelId(); public sealed class EngineConnection { private static EngineConnection instance = null; private static readonly object padlock = new object(); + public HandleNoTunnelId OnNoTunnelId; 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("HP-ZBOOK-SEM", "Sem") //new PC("DESKTOP-TV73FKO", "Wouter"), - new PC("DESKTOP-SINMKT1", "Ralf van Aert"), + //new PC("DESKTOP-SINMKT1", "Ralf van Aert"), //new PC("NA", "Bart") }; @@ -62,6 +64,7 @@ namespace Client { TcpClient client = new TcpClient("145.48.6.10", 6666); stream = client.GetStream(); + initReader(); CreateConnection(); } @@ -69,9 +72,8 @@ namespace Client /// connects to the server and creates the tunnel /// /// the network stream to use - private void CreateConnection() + public void CreateConnection() { - initReader(); WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}"); @@ -119,6 +121,8 @@ namespace Client if (tunnelId == null) { Write("could not find a valid tunnel id!"); + OnNoTunnelId?.Invoke(); + Connected = false; return; } }