diff options
author | fcolin | 2007-02-01 09:58:05 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 09:58:05 +0000 |
commit | 262f9ab293339f6be10d7fb16b58157262833ee5 (patch) | |
tree | e6724737386fb6b27e7ff1ebc78fedc2c834186e /CSharp/Ivy/IvyPPC/IvyClient.cs | |
parent | 06f76c5a56f1f1f8db41149692f6677b9e0e0dcc (diff) | |
download | ivy-csharp-262f9ab293339f6be10d7fb16b58157262833ee5.zip ivy-csharp-262f9ab293339f6be10d7fb16b58157262833ee5.tar.gz ivy-csharp-262f9ab293339f6be10d7fb16b58157262833ee5.tar.bz2 ivy-csharp-262f9ab293339f6be10d7fb16b58157262833ee5.tar.xz |
Utilisateur : Fcolin Date : 19/09/05 Heure : 14:14 Archivé dans $/CSharp/Ivy Commentaire: Passage Nouvel API IVY ( pas teste ) (vss 22)
Diffstat (limited to 'CSharp/Ivy/IvyPPC/IvyClient.cs')
-rw-r--r-- | CSharp/Ivy/IvyPPC/IvyClient.cs | 126 |
1 files changed, 59 insertions, 67 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyClient.cs b/CSharp/Ivy/IvyPPC/IvyClient.cs index de1d413..3ea460c 100644 --- a/CSharp/Ivy/IvyPPC/IvyClient.cs +++ b/CSharp/Ivy/IvyPPC/IvyClient.cs @@ -8,6 +8,7 @@ namespace IvyBus using System;
using System.Collections;
using System.Threading;
+ using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
@@ -101,10 +102,10 @@ namespace IvyBus // protected variables
internal String appName;
- internal IvyClient(Ivy bus, Socket socket)
+ internal IvyClient(Ivy bus, Socket socket, string appname)
{
bindings = Hashtable.Synchronized(new Hashtable());
- appName = "Unknown";
+ appName = appname;
appPort = 0;
this.bus = bus;
this.socket = socket;
@@ -120,7 +121,7 @@ namespace IvyBus // the ID is the couple "host name,application Port", the host name
// information is in the socket itself, the port is not known if we
// initiate the connexion
- stream.sendMsg(IvyStream.MessageType.StartRegexp, bus.applicationPort, bus.appName);
+ stream.sendMsg(IvyStream.MessageType.StartRegexp, bus.applicationPort, Encoding.ASCII.GetBytes( bus.appName ));
// sends our regexps to the peer
lock( bus.bindings.SyncRoot )
{
@@ -129,7 +130,7 @@ namespace IvyBus sendBinding(bind);
}
}
- stream.sendMsg(IvyStream.MessageType.EndRegexp, 0, "");
+ stream.sendMsg(IvyStream.MessageType.EndRegexp, 0, Encoding.ASCII.GetBytes(""));
// spawns a thread to manage the incoming traffic on this
// socket. We should be ready to receive messages now.
clientThread = new Thread(new ThreadStart(this.Run));
@@ -151,17 +152,17 @@ namespace IvyBus /// </summary>
internal void sendApplicationId()
{
- stream.sendMsg( IvyStream.MessageType.ApplicationId, bus.applicationPriority, bus.AppId);
+ stream.sendMsg( IvyStream.MessageType.ApplicationId, bus.applicationPriority, Encoding.ASCII.GetBytes( bus.AppId ) );
}
internal void sendBinding(Ivy.ApplicationBinding bind)
{
- stream.sendMsg(bind.type == Ivy.BindingType.BindRegexp ? IvyStream.MessageType.AddRegexp: IvyStream.MessageType.AddBinding, bind.key, bind.regexp); /* perhaps we should perform some checking here */
+ stream.sendMsg(bind.type == Ivy.BindingType.BindRegexp ? IvyStream.MessageType.AddRegexp: IvyStream.MessageType.AddBinding, bind.key, Encoding.ASCII.GetBytes( bind.regexp )); /* perhaps we should perform some checking here */
}
internal void delBinding(Ivy.ApplicationBinding bind)
{
- stream.sendMsg(bind.type == Ivy.BindingType.BindRegexp ? IvyStream.MessageType.DelRegexp: IvyStream.MessageType.DelBinding, bind.key, "");
+ stream.sendMsg(bind.type == Ivy.BindingType.BindRegexp ? IvyStream.MessageType.DelRegexp: IvyStream.MessageType.DelBinding, bind.key, Encoding.ASCII.GetBytes( "" ));
}
/// <summary> sends a direct message to the peer
/// </summary>
@@ -170,11 +171,11 @@ namespace IvyBus /// <param name='message'>the string that will be match-tested
///
/// </param>
- public void sendDirectMsg(int id, String message)
+ public void sendDirectMsg(int id, string message)
{
try
{
- stream.sendMsg(IvyStream.MessageType.DirectMsg, id, message);
+ stream.sendMsg(IvyStream.MessageType.DirectMsg, id, Encoding.ASCII.GetBytes( message ) );
}
catch (IOException e)
{
@@ -237,10 +238,10 @@ namespace IvyBus IvyBindingSimple.Prepare( message );
foreach (IvyBindingBase bind in bindings.Values )
{
- string[] array = bind.Match(message);
- if (array!=null)
+ IvyArgument args = bind.Match(message);
+ if (args!=null)
{
- stream.sendMsg(IvyStream.MessageType.Msg, bind.key, array);
+ stream.sendMsg(IvyStream.MessageType.Msg, bind.key, args.Serialize());
count++;
}
}
@@ -284,7 +285,8 @@ namespace IvyBus {
IvyStream.MessageType type;
int id;
- string[] args;
+ byte[] data;
+ int length;
try
{
@@ -301,16 +303,16 @@ namespace IvyBus {
try
{
- if ( stream.receiveMsg(out type, out id, out args) )
+ if ( stream.receiveMsg(out type, out id, out data ) )
{
// early stop during readLine()
if (doping && (pingerThread != null))
pingerThread.Interrupt();
- DispatchMsg(type, id, args);
+ DispatchMsg(type, id, data);
}
else
{
- traceDebug("readline null ! leaving the thread");
+ traceDebug("receiveMsg false ! leaving the thread");
break;
}
}
@@ -365,7 +367,7 @@ namespace IvyBus }
- private void recvDie( int id, string[] arg )
+ private void recvDie( int id, string arg )
{
traceDebug("received die Message from " + appName);
// first, I'm not a first class IvyClient any more
@@ -385,10 +387,10 @@ namespace IvyBus if ( !dontkillapp )
Environment.Exit( -1 );
}
- private void recvBye( int id, string[] arg )
+ private void recvBye( int id, string arg )
{
// the peer quits
- traceDebug("received bye Message from " + appName);
+ traceDebug("received bye Message from " + appName + "Raison: "+ arg);
// first, I'm not a first class IvyClient any more
bus.removeClient(this);
// invokes the disconnect applicationListeners
@@ -402,9 +404,8 @@ namespace IvyBus throw new IvyException(ioe.Message);
}
}
- private void recvAddRegexp( int id, string[] arg )
+ private void recvAddRegexp( int id, string regexp )
{
- string regexp = arg[0];
if (bus.CheckRegexp(regexp))
{
try
@@ -423,10 +424,10 @@ namespace IvyBus }
else
{
- traceDebug("regexp Warning exp='" + arg + "' can't match removing from " + appName);
+ traceDebug("regexp Warning exp='" + regexp + "' can't match removing from " + appName);
}
}
- private void recvDelRegexp( int id, string[] arg )
+ private void recvDelRegexp( int id, string arg )
{
lock( bindings.SyncRoot )
{
@@ -436,10 +437,8 @@ namespace IvyBus }
}
- private void recvAddBinding( int id, string[] arg )
+ private void recvAddBinding( int id, string expression )
{
- string expression = arg[0];
-
try
{
IvyBindingSimple bind = new IvyBindingSimple(id, expression);
@@ -456,7 +455,7 @@ namespace IvyBus }
}
- private void recvDelBinding( int id, string[] arg )
+ private void recvDelBinding( int id, string arg )
{
lock( bindings.SyncRoot )
{
@@ -465,24 +464,24 @@ namespace IvyBus bindings.Remove(id);
}
}
- private void recvMsg( int id, string[] arg )
+ private void recvMsg( int id, byte[] arg )
{
bus.callCallback(this, id, arg);
}
- private void recvError( int id, string[] arg )
+ private void recvError( int id, string arg )
{
traceDebug("Error msg " + id + " " + arg);
}
- private void recvApplicationId( int id, string[] arg )
+ private void recvApplicationId( int id, string arg )
{
- clientId = arg[0];
+ clientId = arg;
if ( clientPriority != id )
{
clientPriority = id;
bus.SortClients();
}
}
- private void recvEndRegexp( int id, string[] arg )
+ private void recvEndRegexp( int id, string arg )
{
bus.FireClientConnected(this);
/*
@@ -492,9 +491,9 @@ namespace IvyBus if (bus.ready_message != null)
sendMsg(bus.ready_message);
}
- private void recvStartRegexp( int id, string[] arg )
+ private void recvStartRegexp( int id, string arg )
{
- appName = arg[0];
+ appName = arg;
appPort = id;
if (bus.checkConnected(this))
{
@@ -510,50 +509,51 @@ namespace IvyBus }
}
- private void recvDirectMsg( int id, string[] arg )
+ private void recvDirectMsg( int id, byte[] arg )
{
- bus.FireDirectMessage(this, id, arg[0]);
+
+ bus.FireDirectMessage(this, id, arg );
}
- private void recvPing( int id, string[] arg )
+ private void recvPing( int id, byte[] arg )
{
// I receive a ping. I can answer a pong.
- traceDebug("Ping msg from " + appName + " : " + arg);
- sendPong(arg[0]);
+ traceDebug("Ping msg from " + appName + " : " + Encoding.ASCII.GetString( arg) );
+ sendPong(arg);
}
- private void recvPong( int id, string[] arg )
+ private void recvPong( int id, byte[] arg )
{
traceDebug("Ping msg from " + appName + " : " + arg);
}
- private void DispatchMsg(IvyStream.MessageType msgType, int msgId, string[] msgData)
+ private void DispatchMsg(IvyStream.MessageType msgType, int msgId, byte[] msgData)
{
-
+ string strarg = Encoding.ASCII.GetString( msgData );
switch (msgType)
{
case IvyStream.MessageType.Die:
- recvDie( msgId, msgData );
+ recvDie( msgId, strarg );
break;
case IvyStream.MessageType.Bye:
- recvBye( msgId, msgData );
+ recvBye( msgId, strarg );
break;
case IvyStream.MessageType.AddRegexp:
- recvAddRegexp( msgId, msgData );
+ recvAddRegexp( msgId, strarg );
break;
case IvyStream.MessageType.DelRegexp:
- recvDelRegexp( msgId, msgData );
+ recvDelRegexp( msgId, strarg );
break;
case IvyStream.MessageType.AddBinding:
- recvAddBinding( msgId, msgData );
+ recvAddBinding( msgId, strarg );
break;
case IvyStream.MessageType.DelBinding:
- recvDelBinding( msgId, msgData );
+ recvDelBinding( msgId, strarg );
break;
case IvyStream.MessageType.EndRegexp:
- recvEndRegexp( msgId, msgData );
+ recvEndRegexp( msgId, strarg );
break;
case IvyStream.MessageType.Msg:
@@ -569,18 +569,18 @@ namespace IvyBus break;
case IvyStream.MessageType.Error:
- recvError( msgId, msgData );
+ recvError( msgId, strarg );
break;
case IvyStream.MessageType.StartRegexp:
- recvStartRegexp( msgId, msgData );
+ recvStartRegexp( msgId, strarg );
break;
case IvyStream.MessageType.DirectMsg:
recvDirectMsg( msgId, msgData );
break;
case IvyStream.MessageType.ApplicationId:
- recvApplicationId( msgId, msgData );
+ recvApplicationId( msgId, strarg );
break;
default:
throw new IvyException("protocol error, unknown message type " + msgType);
@@ -588,31 +588,23 @@ namespace IvyBus }
}
- private void sendPong(String s)
+ private void sendPong(byte[] s)
{
stream.sendMsg(IvyStream.MessageType.Pong, 0, s);
}
- public void sendPing(String s)
+ public void sendPing(string s)
{
- stream.sendMsg(IvyStream.MessageType.Ping, 0, s);
+ stream.sendMsg(IvyStream.MessageType.Ping, 0, Encoding.ASCII.GetBytes(s));
}
- private void sendBye()
+ private void sendBye(string message)
{
- stream.sendMsg(IvyStream.MessageType.Bye, 0, "");
- }
- private void sendBye(String message)
- {
- stream.sendMsg(IvyStream.MessageType.Bye, 0, message);
+ stream.sendMsg(IvyStream.MessageType.Bye, 0, Encoding.ASCII.GetBytes( message ));
}
- public void sendDie()
- {
- stream.sendMsg(IvyStream.MessageType.Die, 0, "");
- }
- private void sendDie(String message)
+ public void sendDie(string message)
{
- stream.sendMsg(IvyStream.MessageType.Die, 0, message);
+ stream.sendMsg(IvyStream.MessageType.Die, 0, Encoding.ASCII.GetBytes( message ) );
}
|