diff options
Diffstat (limited to 'CSharp/Ivy/IvyPPC/IvyWatcher.cs')
-rw-r--r-- | CSharp/Ivy/IvyPPC/IvyWatcher.cs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyWatcher.cs b/CSharp/Ivy/IvyPPC/IvyWatcher.cs index ee67ea3..caac8b7 100644 --- a/CSharp/Ivy/IvyPPC/IvyWatcher.cs +++ b/CSharp/Ivy/IvyPPC/IvyWatcher.cs @@ -88,34 +88,38 @@ namespace IvyBus bool running = true;
while (running)
{
- int port;
try
{
len = broadcast.ReceiveFrom(buf, ref tempRemoteEP);
// I was summoned to leave during the receive
- String msg = Encoding.ASCII.GetString(buf);
+ String msg = Encoding.ASCII.GetString(buf,0,len);
remoteEP = (IPEndPoint)tempRemoteEP;
IPAddress remotehost = remoteEP.Address;
traceDebug("BUSWATCHER Receive Broadcast from " + Dns.GetHostName() + ":" + remoteEP.Port);
- // TODO if ( !isInDomain( remotehost ) ) continue;
- String[] st = msg.Split(new char[]{' ','\n'},3);
- if (st.Length != 3)
+ //TODO if ( !isInDomain( remotehost ) ) continue;
+ String[] st = msg.Split(new char[]{' ','\n'},4);
+ if (st.Length != 4)
{
Console.Error.WriteLine("Bad format " + msg);
continue;
}
int version = Int32.Parse(st[0]);
- port = Int32.Parse(st[1]);
+ int port = Int32.Parse(st[1]);
+ string appId = st[2];
+ string appName = st[3];
if (version != Ivy.PROCOCOLVERSION)
{
Console.Error.WriteLine("Ignoring bad protocol version broadcast");
continue;
}
- if ((bus.applicationPort == port))
+ if ((bus.applicationPort == port)) // self Broadcast
continue;
- traceDebug("BUSWATCHER Broadcast de " + Dns.GetHostName() + ":" + remoteEP.Port + " port " + port + " version " + version);
+ traceDebug("BUSWATCHER Broadcast de " + Dns.GetHostName() + ":" + remoteEP.Port + " port " + port +
+ " version " + version +
+ " id " + appId +
+ " name " + appName);
try
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@@ -130,17 +134,22 @@ namespace IvyBus }
catch (IOException jii)
{
+ Console.Error.WriteLine("UDP listener " + jii.Message);
running = false;
}
+// catch (SocketException se)
+// {
+// traceDebug( "watcher socket closed: " + se.Message);
+// }
} // while
}
catch (SocketException se)
{
- traceDebug( "watcher socket closed" );
+ traceDebug( "watcher socket closed: " + se.Message);
}
catch (IOException ioe)
{
- Console.Error.WriteLine( ioe.StackTrace );
+ traceDebug( "watcher thread ended: " + ioe.Message);
}
traceDebug("end of a watcher thread");
}
@@ -167,7 +176,7 @@ namespace IvyBus {
lock(this)
{
- String hello = Ivy.PROCOCOLVERSION + " " + bus.applicationPort + "\n";
+ String hello = Ivy.PROCOCOLVERSION + " " + bus.applicationPort + " " + bus.AppId + " " + bus.AppName + "\n";
listenThread.Start();
byte[] hellob = Encoding.ASCII.GetBytes( hello );
IPEndPoint EPhost = new IPEndPoint(group, port);
|