protected override void Main() { ulong seqNum = 0; var remote1 = new System.Net.IPEndPoint(IPAddress.Loopback, 4001); var remote2 = new System.Net.IPEndPoint(IPAddress.Loopback, 4002); var remote3 = new System.Net.IPEndPoint(IPAddress.Loopback, 4003); while (true) { var msg = new RequestMessage(seqNum); seqNum++; Console.WriteLine("Client: Sending a request with a sequence number " + msg.GetSeqNum()); this.Send(msg, remote1); this.Send(msg, remote2); this.Send(msg, remote3); Thread.Sleep(10000); } }
protected override void Main(ulong id, ulong num_reqs_at_once) { ulong seq_num = 0; this.udpClient = new System.Net.Sockets.UdpClient(6000+(int)id); this.udpClient.Client.ReceiveTimeout = 1000; ulong myaddr = MyAddress64(); int serverIdx = 0; if (num_reqs_at_once == 0) { while (true) { // Make the sequence number a time stamp //var newSeqNum = (ulong) HiResTimer.UtcNow.Ticks; //if (newSeqNum == seqNum) { // seqNum = newSeqNum + 1; //} //else //{ // seqNum = newSeqNum; //} seq_num++; var msg = new RequestMessage(seq_num, myaddr); Trace("Client " + id.ToString() + ": Sending a request with a sequence number " + msg.GetSeqNum() + " to " + ClientBase.endpoints[serverIdx].ToString()); var start_time = HiResTimer.Ticks; this.Send(msg, ClientBase.endpoints[serverIdx]); //foreach (var remote in ClientBase.endpoints) //{ // this.Send(msg, remote); //} // Wait for the reply var received_reply = false; while (!received_reply) { byte[] bytes; try { bytes = Receive(); } catch (System.Net.Sockets.SocketException e) { serverIdx = (serverIdx + 1) % ClientBase.endpoints.Count(); Console.WriteLine("#timeout; rotating to server {0}", serverIdx); Console.WriteLine(e.ToString()); break; } var end_time = HiResTimer.Ticks; Trace("Got the following reply:" + ByteArrayToString(bytes)); if (bytes.Length == 32) { var reply_seq_num = ExtractBE64(bytes, offset: 8); if (reply_seq_num == seq_num) { received_reply = true; // Report time in milliseconds, since that's what the Python script appears to expect Console.Out.WriteLine(string.Format("#req{0} {1} {2} {3}", seq_num, (ulong)(start_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), (ulong)(end_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), id)); //long n = Interlocked.Increment(ref num_reqs); //if (1 == n || n % 1000 == 0) //{ // Console.WriteLine("{0} requests completed.", n); //} } } else { Console.Error.WriteLine("Got an unexpected packet length: " + bytes.Length); } } } } else { UDPListener(num_reqs_at_once); for (ulong i = 0; i < num_reqs_at_once; i++) { var msg = new RequestMessage(seq_num, myaddr); seq_num++; Trace("Client " + id.ToString() + ": Sending a request with a sequence number " + msg.GetSeqNum() + " to " + ClientBase.endpoints[serverIdx].ToString()); this.Send(msg, ClientBase.endpoints[serverIdx]); } } }