summaryrefslogtreecommitdiff
path: root/CSharp/Ivy/IvyPPC
diff options
context:
space:
mode:
Diffstat (limited to 'CSharp/Ivy/IvyPPC')
-rw-r--r--CSharp/Ivy/IvyPPC/IvyClient.cs53
1 files changed, 29 insertions, 24 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyClient.cs b/CSharp/Ivy/IvyPPC/IvyClient.cs
index 2664ef2..29e4e5d 100644
--- a/CSharp/Ivy/IvyPPC/IvyClient.cs
+++ b/CSharp/Ivy/IvyPPC/IvyClient.cs
@@ -64,7 +64,8 @@ namespace IvyBus
{
get
{
- IPHostEntry hostInfo = Dns.GetHostByAddress(((IPEndPoint)socket.RemoteEndPoint).Address);
+ //IPHostEntry hostInfo = Dns.GetHostByAddress(((IPEndPoint)socket.RemoteEndPoint).Address);
+ IPHostEntry hostInfo = Dns.GetHostEntry(((IPEndPoint)socket.RemoteEndPoint).Address);
return hostInfo.HostName;
}
@@ -85,9 +86,8 @@ namespace IvyBus
private string clientId; /* an unique ID for each IvyClient */
private int clientPriority; /* client priority */
- private volatile bool running = false;
private volatile Thread clientThread; // volatile to ensure the quick communication
- private static bool doping = Properties.Settings.Default.IvyPing;
+ private bool doping = false;
private const int PINGTIMEOUT = 5000;
private volatile Thread pingerThread;
@@ -102,10 +102,14 @@ namespace IvyBus
appPort = 0;
this.bus = bus;
this.socket = socket;
+#if (!PocketPC )
+ doping = Properties.Settings.Default.IvyPing;
+#endif
+#if (!PocketPC )
+ socket.SetSocketOption( SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, 1 );
+#endif
- socket.SetSocketOption( SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, 1 );
-
- if ( Properties.Settings.Default.IvyProtocolVersion == 4 )
+ if ( bus.ProtocolVersion == 4 )
stream = new IvyTCPStreamV4( socket, this );
else
stream = new IvyTCPStreamV3(socket, this);
@@ -163,7 +167,7 @@ namespace IvyBus
}
catch (IOException e)
{
- traceDebug("I can't send my message to this client. He probably left");
+ traceDebug("I can't send my message to this client. He probably left "+e.Message);
// first, I'm not a first class IvyClient any more
bus.removeClient(this);
// invokes the Disconnected applicationListeners
@@ -220,7 +224,7 @@ namespace IvyBus
lock( bindings )
{
// hash message in V4 protocol only
- if (Properties.Settings.Default.IvyProtocolVersion == 4)
+ if (bus.ProtocolVersion == 4)
IvyBindingSimple.Prepare(message);
foreach (IvyBindingBase bind in bindings.Values )
{
@@ -240,7 +244,6 @@ namespace IvyBus
if (clientThread == null)
return ;
// Tell Thread to stop.
- running = false;
if ( stream != null )
stream.Close();
if (Thread.CurrentThread != clientThread && clientThread != null)
@@ -269,15 +272,14 @@ namespace IvyBus
/// </summary>
private void Run()
{
- int length;
-
+
try
{
traceDebug("Connected from " + RemoteAddress + ":" + RemotePort);
}
catch (Exception ie)
{
- traceDebug("Interrupted while resolving remote hostname");
+ traceDebug("Interrupted while resolving remote hostname "+ie.Message);
}
traceDebug("Thread started");
@@ -290,7 +292,8 @@ namespace IvyBus
{
// early stop during readLine() //TODO why PinThread Interrupt
if (doping && (pingerThread != null))
- pingerThread.Interrupt();
+ //pingerThread.Interrupt();
+ pingerThread.Abort();
}
else
{
@@ -300,20 +303,20 @@ namespace IvyBus
}
catch ( ObjectDisposedException e )
{
- traceDebug( "ivyclient socket closed" );
+ traceDebug( "ivyclient socket closed "+e.Message );
running = false;
break;
}
catch (IvyException ie)
{
- Console.Error.WriteLine( ie.Message );
- Console.Error.WriteLine( ie.StackTrace);
+ Console.Error.WriteLine(ie.Message);
+ Console.Error.WriteLine(ie.StackTrace);
running = false;
break;
}
catch (SocketException se)
{
- traceDebug( "ivyclient socket closed" );
+ traceDebug( "ivyclient socket closed "+se.Message );
running = false;
break;
}
@@ -327,8 +330,8 @@ namespace IvyBus
else
{
traceDebug("abnormally Disconnected from " + RemoteAddress + ":" + RemotePort);
- Console.Error.WriteLine( e.Message );
- Console.Error.WriteLine( e.StackTrace);
+ Console.Error.WriteLine(e.Message);
+ Console.Error.WriteLine(e.StackTrace);
}
running = false;
break;
@@ -367,7 +370,7 @@ namespace IvyBus
throw new IvyException(ioe.Message);
}
if ( !dontkillapp )
- System.Windows.Forms.Application.Exit();
+ System.Windows.Forms.Application.Exit();
}
override internal void TokenBye(ushort err, string arg)
{
@@ -420,7 +423,7 @@ namespace IvyBus
}
catch (KeyNotFoundException ex)
{
- Console.WriteLine("DelBinding " + ex.Message);
+ Console.Error.WriteLine("DelBinding " + ex.Message);
}
}
}
@@ -495,7 +498,7 @@ namespace IvyBus
private void traceDebug(String s)
{
if (bus.Debug)
- Console.Out.WriteLine("-->IvyClient " + bus.appName + ":" + appName + "<-- " + s);
+ Console.Error.WriteLine("-->IvyClient " + bus.appName + ":" + appName + "<-- " + s);
}
internal bool isPinging = false;
@@ -510,8 +513,9 @@ namespace IvyBus
Thread.Sleep(PINGTIMEOUT);
stream.TokenPing("are you here ?");
}
- catch (ThreadInterruptedException ie)
+ catch (ThreadAbortException ie)
{
+ traceDebug("Pinger Thread killed "+ie.Message);
}
}
traceDebug("Pinger Thread stopped");
@@ -519,7 +523,8 @@ namespace IvyBus
public virtual void stopPinging()
{
isPinging = false;
- pingerThread.Interrupt();
+ //pingerThread.Interrupt();
+ pingerThread.Abort();
}
}
} \ No newline at end of file