async public static void SendRequestToClient(JStruct js) { var client = await CallExternalAppliation((c) => { c.SendByStream2(js.JSerialize().ToByteArray(Encoding.ASCII), Engine_Code.Received); Logger.Log($"Request Sent from Engine: {js.JsMessage}"); }); if (client == null) { Logger.Log($"Couldn't Connect to External App", "", Logger.ErrorType.Warrning); } }
private void ResolveTcpRequest(int code, TcpClient client, Net.ResponseBytes resp) { switch (code) { case Engine_Code.Message: { var js = new JStruct().FromServer(resp); DefaultScene.Actions.Add(() => { new Urho3DNet.MessageBox(DefaultScene.scene.Context, js.JsMessage); js = new JStruct(); js.JsMessage = "Message Sent"; SendRequestToClient(js); }); break; } case Engine_Code.DrawGeometry: { try { var js = new JStruct().FromServer(resp); var geometryFolderPaths = "".JDeserializemyData(js.JsData); var geometryFilePaths = Directory.GetFiles(geometryFolderPaths).ToList(); DefaultScene.Actions.Add(() => { DefaultScene.Instance.DrawGeometryFromRevit(geometryFilePaths); }); } catch (Exception ex) { ex.Log("Error DrawingGeometry from TCP", Logger.ErrorType.Warrning); } break; } default: break; } }
async private void handelconnection(TcpClient _client) { var client = _client; var nstream = client.GetStream(); try { Logger.Log($"Received data: from {_client.Client.RemoteEndPoint.AddressFamily.ToString()}"); var resp = await client.ReadfromStream2(); if (resp.ResponseByte.Length == 0) { client.Dispose(); return; } var data = File.ReadAllBytes(resp.SavedDataPath); int Code = BitConverter.ToInt32(resp.ResponseByte, 0); Logger.Log($"Sending Code: {Code}"); try { ResolveTcpRequest(Code, client, resp); } catch (Exception ex) { var js = new JStruct(); js.JsMessage = ex.ToString(); client.SendByStream2(js.JSerialize().ToByteArray(Encoding.ASCII), Engine_Code.Failed); Logger.Log($"Method Number not found"); ex.Log("Connecting from Engine", Logger.ErrorType.Warrning); } } catch (Exception ex) { ex.Log(ex.Message, Logger.ErrorType.Error); } client?.Close(); }