1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
using System;
using IvyBus;
using System.Threading;
using System.Globalization;
using System.Collections.Specialized;
namespace IvyPerf
{
/// <summary>
/// Description résumée de Class1.
/// </summary>
class IvyPerf
{
static Ivy bus;
static double origin = 0;
static double currentTime() // en ms
{
double time;
time = (double)DateTime.Now.Ticks / (double)TimeSpan.TicksPerMillisecond;
//time = Environment.TickCount;
return time;
}
[IvyBinding("^ping ts=(.*)")]
static void Reply(IvyClient client, string[] args)
{
bus.sendMsg("pong ts={0} tr={1}", args[0], currentTime() - origin );
}
[IvyBinding("^pong ts=(.*) tr=(.*)")]
static void Pong(IvyClient client, string[] args)
{
double current = currentTime() - origin;
double ts = double.Parse( args[0], bus.Culture );
double tr = double.Parse(args[1], bus.Culture );
double roundtrip1 = tr - ts;
double roundtrip2 = current - tr;
double roundtrip3 = current - ts;
Console.WriteLine("round trip {0} {1} {2}", roundtrip1, roundtrip2, roundtrip3);
}
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int timeout = 1000;
if (args.Length > 0)
timeout = int.Parse(args[0]);
StringCollection my_messsages = new StringCollection();
my_messsages.Add("ping");
my_messsages.Add("pong");
my_messsages.Add("IvyPref");
bus = new Ivy("IvyPerf", "IvyPref ready");
bus.BindingFilter += new Ivy.ClientRemoveBindingHandler(bus_BindingFilter);
bus.SentMessageClasses = my_messsages;
bus.AutoBinding(typeof(IvyPerf));
bus.start(null);
origin = currentTime();
while( true )
{
Thread.Sleep( timeout );
int count = bus.sendMsg("ping ts={0}", currentTime() - origin );
if ( count == 0 ) Console.Write( "." );
}
}
static void bus_BindingFilter(IvyClient app, string arg)
{
Console.WriteLine( "The app {0} regexp {1} was Filtred.", app.ApplicationName,arg);
}
}
}
|