private static void SendAndWait() { string ipPort = InputString("IP:port:", lastIpPort, false); string userInput = InputString("Data:", null, false); int timeoutMs = InputInteger("Timeout (milliseconds):", 5000, true, false); try { SyncResponse resp = server.SendAndWait(ipPort, 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()); } }
private static void SendAndWait() { string ipPort = InputString("IP:port:", _LastIpPort, false); string userInput = InputString("Data:", null, false); int timeoutMs = InputInteger("Timeout (milliseconds):", 5000, true, false); try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); SyncResponse resp = _Server.SendAndWait(timeoutMs, ipPort, userInput); stopwatch.Stop(); 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)); Console.WriteLine("Client responded in {0} ms/{1} ticks.", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } }
private static void ServerTask() { for (int i = 0; i < _NumIterations; i++) { int waitVal = _Random.Next(0, 12); Task.Delay(waitVal).Wait(); if (waitVal % 3 == 0) { Console.WriteLine("[server] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Sending large message"); _Server.Send(_ClientIpPort, _DataLargeBytes); } else if (waitVal % 2 == 0) { Console.WriteLine("[server] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Sending small message"); _Server.Send(_ClientIpPort, _DataSmallBytes); } else { Console.WriteLine("[server] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Send and wait small message"); try { SyncResponse syncResponse = _Server.SendAndWait(_ClientIpPort, _SendAndWaitInterval, _DataSmallBytes); Console.WriteLine("[server] Sync response received"); } catch (Exception e) { Console.WriteLine("[server] Sync response not received: " + e.Message); } } } Console.WriteLine("[server] Finished"); }
static void ServerTask() { try { SyncResponse resp = server.SendAndWait(clientIpPort, 5000, "Here's your request from the server!"); if (resp == null) { Console.WriteLine("Server did not receive response from client"); } else { Console.WriteLine("Server received response from " + clientIpPort + ": " + Encoding.UTF8.GetString(resp.Data)); } } catch (Exception e) { Console.WriteLine("Server exception: " + e.Message); } }