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
|
using System;
using IvyBus;
using System.Threading;
using System.Globalization;
namespace IvyPerf
{
/// <summary>
/// Description résumée de Class1.
/// </summary>
class IvyPerf
{
static Ivy bus;
// manque d'homogeneitee format float en langue US
static CultureInfo c;
static double currentTime() // en ms
{
double time;
time = (double)DateTime.Now.Ticks / (double)TimeSpan.TicksPerMillisecond;
//time = Environment.TickCount;
return time;
}
static void Reply(IvyClient client, string[] args)
{
bus.sendMsg(c,"pong ts={0} tr={1}", args, currentTime());
}
static void Pong(IvyClient client, string[] args)
{
double current = currentTime();
double ts = double.Parse( args[0], c );
double tr = double.Parse(args[1], c);
double roundtrip1 = tr-ts;
double roundtrip2 = current - ts;
Console.WriteLine( "round trip {0} {1}", roundtrip1 , roundtrip2 );
}
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
c = new CultureInfo("en-us");
bus = new Ivy("IvyPerf", "IvyPref ready");
bus.bindMsg( "^ping ts=(.*)", new Ivy.MessageHandler( Reply ) );
bus.bindMsg( "^pong ts=(.*) tr=(.*)", new Ivy.MessageHandler( Pong ) );
//bus.bindSimpleMsg( "ping:ts", new Ivy.MessageHandler( Reply ) );
//bus.bindSimpleMsg( "pong:ts,tr", new Ivy.MessageHandler( Pong ) );
bus.start(null);
while( true )
{
Thread.Sleep( 1000 );
int count = bus.sendMsg(c,"ping ts={0}", currentTime());
if ( count == 0 ) Console.Write( "." );
}
}
}
}
|