private static void ClientTask() { for (int i = 0; i < _NumIterations; i++) { int waitVal = _Random.Next(0, 12); Task.Delay(waitVal).Wait(); if (waitVal % 3 == 0) { Console.WriteLine("[client] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Sending large message"); _Client.Send(_DataLargeBytes); } else if (waitVal % 2 == 0) { Console.WriteLine("[client] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Sending small message"); _Client.Send(_DataSmallBytes); } else { Console.WriteLine("[client] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Send and wait small message"); try { SyncResponse syncResponse = _Client.SendAndWait(_SendAndWaitInterval, _DataSmallBytes); Console.WriteLine("[client] Sync response received"); } catch (Exception e) { Console.WriteLine("[client] Sync response not received: " + e.Message); } } } Console.WriteLine("[client] Finished"); }
private static void SendAndWait() { string userInput = InputString("Data:", null, false); int timeoutMs = InputInteger("Timeout (milliseconds):", 5000, true, false); try { SyncResponse resp = client.SendAndWait(timeoutMs, userInput); if (resp.Metadata != null && resp.Metadata.Count > 0) { Console.WriteLine("Metadata:"); foreach (KeyValuePair <object, object> curr in resp.Metadata) { Console.WriteLine(" " + curr.Key.ToString() + ": " + curr.Value.ToString()); } } Console.WriteLine("Response: " + Encoding.UTF8.GetString(resp.Data)); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } }
static void ClientTask() { try { SyncResponse resp = client.SendAndWait(5000, "Here's your request from the client!"); if (resp == null) { Console.WriteLine("Client did not receive response from server"); } else { Console.WriteLine("Client received response from server: " + Encoding.UTF8.GetString(resp.Data)); } } catch (Exception e) { Console.WriteLine("Client exception: " + e.Message); } }
/// <summary> /// Function that sends a request to a Host and get answer. /// </summary> /// <param name="msg">The message that has to be sent.</param> /// <returns>Host resonse.</returns> public SyncResponse SendMessage(string msg) { byte[] b = GetBytesFromString(msg); return(clientH.SendAndWait(msBeforeTimeOut, b)); }