Author: remi
Date: 2008-12-02 13:55:20 +0100 (Tue, 02 Dec 2008)
New Revision: 2983

Modified:
   
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/Unit1.pas
Log:
* improved internet connection detection.
* fixed a not handled exception.

Modified: 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/Unit1.pas
===================================================================
--- 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/Unit1.pas
     2008-12-02 12:19:23 UTC (rev 2982)
+++ 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/Unit1.pas
     2008-12-02 12:55:20 UTC (rev 2983)
@@ -29,7 +29,7 @@
   Wsocket,
   MagentaMonsock, MagentaMonpcap, MagentaPacket32, MagentaPcap,
   MagentaPackhdrs, Magsubs1, MagClasses, StdCtrls, HttpProt,
-  IdBaseComponent, IdComponent, IdIPWatch, Check;
+  IdBaseComponent, IdComponent, IdIPWatch, IdHTTP, IdException;
 
 const
   MSN_MSG_REQ = 
'http://127.0.0.1:270/0/status/send?name=chatter&value=MSN|MSG|Nickname|%s';
@@ -86,6 +86,29 @@
   SetLength(Result, Rp - PChar(Result));
 end;
 
+{*
+ * \brief Check if the internet connection is available.
+ * \return true or false.
+ *}
+function getInternetConnectionAvailable : boolean;
+var
+  idHTTP : TIdHTTP;
+begin
+  idHTTP := TIdHTTP.Create(nil);
+  idHTTP.ConnectTimeout := 6400;
+  idHTTP.Request.CacheControl := 'no-cache';
+  idHTTP.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 
5.1)';
+  result := false;
+  try
+    idHTTP.Head('http://www.google.be/');
+    result := true;
+  except
+  end;
+  idHttp.Disconnect;
+  idHttp.DisconnectSocket;
+  idHTTP.Free;
+end;
+
 {**
  * Match the MSN messages.
  *}
@@ -153,8 +176,6 @@
  * On frame creation.
  *}
 procedure TForm1.FormCreate(Sender: TObject);
-var
-  ip : string;
 begin
   // Create the socket monitor
   MonitorSocket := TMonitorSocket.Create(self);
@@ -174,37 +195,18 @@
     end else
     // At least one IP address found
     begin
-      ip := '';
-      // Check internet status part 1
-      try
-        CheckIPConnection('www.google.be', ip);
-      except
-        ip := '';
-      end;
-      // No Internet connection - failed
-      if ip = '' then
+      // Check internet status
+      if not getInternetConnectionAvailable then
       begin
-        sleep(2000);
-        application.ProcessMessages;
+        continue;
       end else
-      // Internet connection found
       begin
-        // Check internet status part 2
-        try
-          sleep(1000);
-          application.ProcessMessages;
-          HttpCli1.URL := 'www.google.fr';
-          HttpCli1.Get;
-        // Internet connection is not fully available - failed
-        except
-          continue;
-        end;
-        // Ok internet connection is available - OK quit the loop
+        sleep(1000);
         break;
       end;
     end;
   end;
-  
+
   // Retrieve the local IP
   if LocalIPList.Count > 0 then
   begin
@@ -225,7 +227,12 @@
     try
       MonitorSocket.StartMonitor(true);
     except
-      MonitorSocket.StartMonitor(false);
+      try
+        MonitorSocket.StartMonitor(false);
+      except
+        // Can't monitoring your network card ...
+        application.Terminate;
+      end;
     end;
   end else
   begin


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to