creating connection with new reading stuff works
This commit is contained in:
@@ -50,6 +50,19 @@ namespace RH_Engine
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetSerial(string json)
|
||||||
|
{
|
||||||
|
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
||||||
|
return jsonData.serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetID(string json)
|
||||||
|
{
|
||||||
|
dynamic d = JsonConvert.DeserializeObject(json);
|
||||||
|
return d.id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetTunnelID(string json)
|
public static string GetTunnelID(string json)
|
||||||
{
|
{
|
||||||
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ namespace RH_Engine
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static ServerResponseReader serverResponseReader;
|
private static ServerResponseReader serverResponseReader;
|
||||||
|
private static string sessionId = string.Empty;
|
||||||
|
private static string tunnelId = string.Empty;
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
||||||
@@ -42,7 +44,24 @@ namespace RH_Engine
|
|||||||
|
|
||||||
public static void HandleResponse(string message)
|
public static void HandleResponse(string message)
|
||||||
{
|
{
|
||||||
Console.WriteLine("GOT MESSAGE FROM CALLBACK!!!!! " + message);
|
//Console.WriteLine("GOT MESSAGE FROM CALLBACK!!!!! " + message);
|
||||||
|
|
||||||
|
string id = JSONParser.GetID(message);
|
||||||
|
Console.WriteLine("got id : " + id);
|
||||||
|
|
||||||
|
// because the first messages don't have a serial, we need to check on the id
|
||||||
|
if (id == "session/list")
|
||||||
|
{
|
||||||
|
sessionId = JSONParser.GetSessionID(message,PCs);
|
||||||
|
} else if (id == "tunnel/create")
|
||||||
|
{
|
||||||
|
tunnelId = JSONParser.GetTunnelID(message);
|
||||||
|
if (tunnelId == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("could not find a valid tunnel id!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -92,6 +111,7 @@ namespace RH_Engine
|
|||||||
|
|
||||||
return Encoding.UTF8.GetString(buffer, 0, totalRead);
|
return Encoding.UTF8.GetString(buffer, 0, totalRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// connects to the server and creates the tunnel
|
/// connects to the server and creates the tunnel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -100,25 +120,19 @@ namespace RH_Engine
|
|||||||
{
|
{
|
||||||
initReader(stream);
|
initReader(stream);
|
||||||
|
|
||||||
WriteTextMessage(stream, "{\r\n\"id\" : \"session/list\"\r\n}");
|
WriteTextMessage(stream, "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
|
||||||
//string id = JSONParser.GetSessionID(ReadPrefMessage(stream), PCs);
|
|
||||||
|
|
||||||
//string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + id + "\"}}";
|
// wait until we have got a sessionId
|
||||||
|
while (sessionId == string.Empty) { }
|
||||||
|
|
||||||
|
string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + sessionId + "\"}}";
|
||||||
|
|
||||||
//WriteTextMessage(stream, tunnelCreate);
|
WriteTextMessage(stream, tunnelCreate);
|
||||||
|
|
||||||
//string tunnelResponse = ReadPrefMessage(stream);
|
// wait until we have a tunnel id
|
||||||
|
while (tunnelId == string.Empty) { }
|
||||||
//Console.WriteLine(tunnelResponse);
|
Console.WriteLine("got tunnel id! sending commands...");
|
||||||
|
//sendCommands(stream, tunnelId);
|
||||||
//string tunnelID = JSONParser.GetTunnelID(tunnelResponse);
|
|
||||||
//if (tunnelID == null)
|
|
||||||
//{
|
|
||||||
// Console.WriteLine("could not find a valid tunnel id!");
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//sendCommands(stream, tunnelID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -139,6 +153,8 @@ namespace RH_Engine
|
|||||||
Console.WriteLine(ReadPrefMessage(stream));
|
Console.WriteLine(ReadPrefMessage(stream));
|
||||||
string command;
|
string command;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//command = mainCommand.AddBikeModel();
|
//command = mainCommand.AddBikeModel();
|
||||||
|
|
||||||
//WriteTextMessage(stream, command);
|
//WriteTextMessage(stream, command);
|
||||||
|
|||||||
Reference in New Issue
Block a user