Browse files

reconnecting to Crossfire if no response in 3 sec

  • Loading branch information...
1 parent 05ce632 commit 5c289d9dcf1d795a1e203a9d9bc53420efd2ab7a @olegzu committed Aug 22, 2012
Showing with 36 additions and 1 deletion.
  1. +29 −1 CrossFire.cs
  2. +7 −0 README.md
View
30 CrossFire.cs
@@ -32,6 +32,20 @@ public class CrossFire
public delegate void StringHandler(string data);
public static event StringHandler NewData;
+ static System.Timers.Timer SendCommandTimeOut;
+
+ static CrossFire()
+ {
+ NewData += new StringHandler(CrossFire_NewData);
+ SendCommandTimeOut = new System.Timers.Timer(4000);
+ SendCommandTimeOut.Elapsed += new System.Timers.ElapsedEventHandler(SendCommandTimeOut_Elapsed);
+ }
+
+ static void CrossFire_NewData(string data)
+ {
+ SendCommandTimeOut.Enabled = false;
+ }
+
public static void Connect()
{
new Thread(
@@ -128,7 +142,8 @@ public static void Connect()
public static void Disconnect()
{
- networkStream.Close();
+ if (networkStream != null)
+ networkStream.Close();
//socket.Close();
}
@@ -225,9 +240,22 @@ public static void SendCommand(string type, string command, string contextId = n
data += "\r\n}";
}
data += "}\r\n";
+ SendCommandTimeOut.Enabled = true;
SendData(data);
}
+ static void SendCommandTimeOut_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+ {
+ SendCommandTimeOut.Enabled = false;
+ ReConnect();
+ }
+
+ private static void ReConnect()
+ {
+ Disconnect();
+ Connect();
+ }
+
public static void GetListContexts()
{
SendData("{\n" +
View
7 README.md
@@ -0,0 +1,7 @@
+CrossfireConnect
+Test C# connection to Crossfire (Firebug extension to allow remote clients to connect to Firebug).
+Need your help. Have BUG. After some time do not send commands to Crossfire.
+Messages from Crossfire are accepted all the time
+
+I have solved problem by reconnecting to Crossfire if no response in 3 sec.
+It is not correct. Bug remain

0 comments on commit 5c289d9

Please sign in to comment.