Author: remi
Date: 2009-02-10 10:40:02 +0100 (Tue, 10 Feb 2009)
New Revision: 3593

Modified:
   
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/ChatterTuxMain.pas
   
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/InternetConnection.pas
Log:
* fixed the way of retrieving the Internet connection status.
* fixed the way of retrieving the current local IP address.
* added some logs

Modified: 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/ChatterTuxMain.pas
===================================================================
--- 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/ChatterTuxMain.pas
    2009-02-10 09:39:51 UTC (rev 3592)
+++ 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/ChatterTuxMain.pas
    2009-02-10 09:40:02 UTC (rev 3593)
@@ -167,6 +167,7 @@
  *}
 procedure TService1.ServiceExecute(Sender: TService);
 begin
+  LogInfo('Execute the service');
   internetConn.Resume;
 
   while not Terminated do

Modified: 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/InternetConnection.pas
===================================================================
--- 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/InternetConnection.pas
        2009-02-10 09:39:51 UTC (rev 3592)
+++ 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/InternetConnection.pas
        2009-02-10 09:40:02 UTC (rev 3593)
@@ -3,8 +3,7 @@
 interface
 
 uses
-  Classes, Windows,
-  IdBaseComponent, IdComponent, IdHTTP, IdException;
+  SysUtils, Classes, Windows, Logger, WinSock, Ping;
 
 type
 
@@ -37,27 +36,50 @@
 // 
=============================================================================
 
 {*
+ * \brief Get the current local ip address.
+ * \return The current local ip address.
+ *}
+function getLocalIp : string;
+type
+  TaPInAddr = array [0..10] of PInAddr;
+  PaPInAddr = ^TaPInAddr;
+var
+  phe : PHostEnt;
+  pptr : PaPInAddr;
+  Buffer : array [0..63] of char;
+  i : Integer;
+  GInitData : TWSADATA;
+begin
+  WSAStartup($101, GInitData);
+  Result := '';
+  GetHostName(Buffer, SizeOf(Buffer));
+  phe :=GetHostByName(buffer);
+  if phe = nil then Exit;
+  pptr := PaPInAddr(Phe^.h_addr_list);
+  i := 0;
+  while pptr^[i] <> nil do
+  begin
+    result:=StrPas(inet_ntoa(pptr^[i]^));
+    Inc(i);
+  end;
+  WSACleanup;
+end;
+
+{*
  * \brief Check if the internet connection is available.
  * \return the working ip or None.
  *}
 function getInternetConnectionAvailable : string;
 var
-  idHTTP : TIdHTTP;
+  ping : TPing;
 begin
-  idHTTP := TIdHTTP.Create(nil);
-  idHTTP.ConnectTimeout := 30000;
-  idHTTP.Request.CacheControl := 'no-cache';
-  idHTTP.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 
5.1)';
-  idHTTP.HandleRedirects := true;
-  idHTTP.RedirectMaximum := 100;
   result := 'None';
-  try
-    idHTTP.Head('http://www.google.com/');
-    result := idHTTP.Socket.Binding.IP;
-  except
-  end;
-  idHttp.Disconnect;
-  idHTTP.Free;
+  ping := TPing.Create(nil);
+  ping.Address := 'www.google.com';
+  if ping.Ping <> 1 then
+    exit;
+  result := getLocalIp;
+  ping.Free;
 end;
 
 // 
=============================================================================
@@ -74,7 +96,10 @@
 begin
   P_connected := false;
   P_ip := 'None';
+  accu := 0;
 
+  LogInfo('Connection thread started');
+
   while not self.Terminated do
   begin
     // If not connected
@@ -90,7 +115,8 @@
           P_onConnected(myIp);
         P_connected := true;
         continue;
-      end;
+      end else
+        LogInfo('No connection available');
     end else
     // If Connected
     begin


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to