using System;
using IvyBus;
using System.Threading;
using System.Globalization;
namespace IvyPerf
{
///
/// Description résumée de Class1.
///
class IvyPerf
{
static Ivy bus;
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());
}
[IvyBinding("^pong ts=(.*) tr=(.*)")]
static void Pong(IvyClient client, string[] args)
{
double current = currentTime();
double ts = double.Parse( args[0], bus.Culture );
double tr = double.Parse(args[1], bus.Culture );
double roundtrip1 = tr-ts;
double roundtrip2 = current - ts;
Console.WriteLine( "round trip {0} {1}", roundtrip1 , roundtrip2 );
}
///
/// Point d'entrée principal de l'application.
///
[STAThread]
static void Main(string[] args)
{
bus = new Ivy("IvyPerf", "IvyPref ready");
bus.AutoBinding(typeof(IvyPerf));
//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("ping ts={0}", currentTime());
if ( count == 0 ) Console.Write( "." );
}
}
}
}