added reconnecting to the vr server when no tunnel id is found
This commit is contained in:
@@ -27,16 +27,24 @@ namespace Client
|
|||||||
this.client = new TcpClient();
|
this.client = new TcpClient();
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
|
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
|
||||||
|
|
||||||
initEngine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initEngine()
|
private void initEngine()
|
||||||
{
|
{
|
||||||
engineConnection = EngineConnection.INSTANCE;
|
engineConnection = EngineConnection.INSTANCE;
|
||||||
|
engineConnection.OnNoTunnelId = retryEngineConnection;
|
||||||
if (!engineConnection.Connected) engineConnection.Connect();
|
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)
|
private void OnConnect(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
this.client.EndConnect(ar);
|
this.client.EndConnect(ar);
|
||||||
|
|||||||
@@ -7,20 +7,22 @@ using System.Net.Sockets;
|
|||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
public delegate void HandleSerial(string message);
|
public delegate void HandleSerial(string message);
|
||||||
|
public delegate void HandleNoTunnelId();
|
||||||
|
|
||||||
public sealed class EngineConnection
|
public sealed class EngineConnection
|
||||||
{
|
{
|
||||||
private static EngineConnection instance = null;
|
private static EngineConnection instance = null;
|
||||||
private static readonly object padlock = new object();
|
private static readonly object padlock = new object();
|
||||||
|
public HandleNoTunnelId OnNoTunnelId;
|
||||||
|
|
||||||
|
|
||||||
private static PC[] PCs = {
|
private static PC[] PCs = {
|
||||||
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
||||||
//new PC("T470S", "Shinichi"),
|
//new PC("T470S", "Shinichi"),
|
||||||
//new PC("DESKTOP-DHS478C", "semme"),
|
//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-TV73FKO", "Wouter"),
|
||||||
new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||||
//new PC("NA", "Bart")
|
//new PC("NA", "Bart")
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,6 +64,7 @@ namespace Client
|
|||||||
{
|
{
|
||||||
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
||||||
stream = client.GetStream();
|
stream = client.GetStream();
|
||||||
|
initReader();
|
||||||
CreateConnection();
|
CreateConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +72,8 @@ namespace Client
|
|||||||
/// connects to the server and creates the tunnel
|
/// connects to the server and creates the tunnel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">the network stream to use</param>
|
/// <param name="stream">the network stream to use</param>
|
||||||
private void CreateConnection()
|
public void CreateConnection()
|
||||||
{
|
{
|
||||||
initReader();
|
|
||||||
|
|
||||||
WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
|
WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
|
||||||
|
|
||||||
@@ -119,6 +121,8 @@ namespace Client
|
|||||||
if (tunnelId == null)
|
if (tunnelId == null)
|
||||||
{
|
{
|
||||||
Write("could not find a valid tunnel id!");
|
Write("could not find a valid tunnel id!");
|
||||||
|
OnNoTunnelId?.Invoke();
|
||||||
|
Connected = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user