public static byte[] SendFile(string path, ushort selectedAlgortihm, ClientWindow window) { try { byte[] fileBytes = ReadFile(path), requestBytes = CreateFTRequestBytes(fileBytes, selectedAlgortihm); using (AsynchronousClient client = new AsynchronousClient()) { client.ExceptionReport += (sender, e) => { if (e.Exception.Message == "lol") { return; } //window.Dispatcher.BeginInvoke((MethodInvoker)(() => // MessageBox.Show(e.Exception.Message, Application.ProductName, // MessageBoxButtons.OK, MessageBoxIcon.Error))); }; client.Connect(Dns.GetHostName()); client.SendData(requestBytes); var result = client.ReceiveResponse(); return(result); } } catch (Exception ex) { throw ex; } }
public static byte[] SendFile(byte[] dataToPredict, ushort selectedAlgortihm, AsynchronousClient client) { try { byte[] requestBytes = CreateFTRequestBytes(dataToPredict, selectedAlgortihm); using (client) { client.ExceptionReport += (sender, e) => { client.Dispose(); //window.Dispatcher.BeginInvoke((MethodInvoker)(() => // MessageBox.Show(e.Exception.Message, Application.ProductName, // MessageBoxButtons.OK, MessageBoxIcon.Error))); }; client.Connect(Dns.GetHostName()); client.SendData(requestBytes); var result = client.ReceiveResponse(); return(result); } } catch (Exception ex) { throw ex; } }
static void Main(string[] args) { string msg = Console.ReadLine(); AsynchronousClient client = new AsynchronousClient(Dns.GetHostName(), 11000, msg); new Thread(new ThreadStart(AsynchronousClient.StartClient)).Start(); while (true) { msg = Console.ReadLine(); AsynchronousClient.SendData(msg); } }
public static bool RequestSendSms(string number, string content) { AsynchronousClient client = null; try { string SmsServer = ConfigurationManager.AppSettings["SmsServer"]; client = new AsynchronousClient(SmsServer, 1450, null); if (client != null && client.IsConnected()) { Dictionary <string, string> dictDataSend = new Dictionary <string, string>(); dictDataSend.Add("PHONE_NUMBER", number); dictDataSend.Add("CONTENT_SMS", content); ItemData itemData = new ItemData(); itemData.Action = "SMS_REGISTRATION_CODE"; itemData.StateObject = dictDataSend; byte[] recv = client.SendData(itemData.GetBytes()); if (recv != null) { ItemData recvData = ItemData.Parse(recv); if (client != null && client.IsConnected()) { client.Disconnect(); } return((bool)recvData.StateObject); } } if (client != null && client.IsConnected()) { client.Disconnect(); } return(false); } catch { if (client != null && client.IsConnected()) { client.Disconnect(); } return(false); } }
static void Main(string[] args) { LoggingData.ClearLogs(); client = new AsynchronousClient("localhost", 1450, null); Console.ReadLine(); ItemData itemData = new ItemData(); itemData.Action = "SMS_REGISTRATION_CODE"; itemData.StateObject = "Test sms"; while (true) { if (client != null) { byte[] recv = client.SendData(itemData.GetBytes()); if (recv != null) { ItemData recvData = ItemData.Parse(recv); Console.WriteLine(recvData.StateObject.ToString()); } } Console.ReadLine(); } }